Search Terms
noImplicitThis noImplicitAny code fix this annotation
Suggestion
#14786 added a code fix for --noImplicitAny failures. Can we have the same for --noImplicitThis?
In cases where the this can be inferred for all locations that directly call a function, can TypeScript make a best guess of what the this type is meant to be?
Use Cases
In older code that uses fancy function assignments and isn't yet onboarded onto --noImplicitThis, it can be a bit of a pain to add them in.
Examples
interface NameBox {
name: string;
printName(): void;
}
// Code fix suggestion to add a `this: NameBox`?
function printName() {
console.log(this.name);
}
const createNameBox = (name: string): NameBox => ({
name,
printName,
});
This example seems like it could be an inferrable one, since we can tell that printName is used as a member of a NameBox.
Checklist
My suggestion meets these guidelines:
Search Terms
noImplicitThis noImplicitAny code fix this annotation
Suggestion
#14786 added a code fix for
--noImplicitAnyfailures. Can we have the same for--noImplicitThis?In cases where the
thiscan be inferred for all locations that directly call afunction, can TypeScript make a best guess of what thethistype is meant to be?Use Cases
In older code that uses fancy
functionassignments and isn't yet onboarded onto--noImplicitThis, it can be a bit of a pain to add them in.Examples
This example seems like it could be an inferrable one, since we can tell that
printNameis used as a member of aNameBox.Checklist
My suggestion meets these guidelines: