Loading...
type Options = {
data: { count: number };
methods: Record<string, (this: any) => void>;
};type Options<D, M> = {
data: D;
methods: M & ThisType<D & M>;
};Instead of any, this inside each method is typed as the data plus the other methods.
ThisType<T> to add properties to the object, when it only types this inside it.noImplicitThis is enabled, otherwise ThisType has no effect.ThisType<T> appears in the contextual type of an object literal, e.g. a parameter of an options builder.No, it is an empty marker interface. It only changes how the compiler types this in an object literal.
It needs noImplicitThis, which strict turns on, and it must be part of the object literal's contextual type.