microsoft / microsoft/TypeScript
Check inferred `this` parameter against interface requirement `this: void`
@sandersn ci sta già lavorando.
Dal 15/6/2021.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
Bug Report
🔎 Search Terms
interface method requirement this: void
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
Playground link with relevant code
💻 Code
interface Foo {
method(this: void): number;
}
class Example implements Foo {
x = 3;
method() { return this.x; } // no error
}
🙁 Actual behavior
No error
🙂 Expected behavior
Error because the method implementation's implicit this: Example is not compatible with the interface requirement this: void.
The @typescript-eslint/unbound-method lint rule uses this: void as an annotation indicating the method is allowed to be used without binding this. However, there seems to be no checking from the TS compiler as to whether an inferred this type in a method implementation matches an interface requirement. Thus the lint rule can help you add this: void to the interface if you intend for functions to be usable when not bound... but neither the linter nor compiler currently help prevent runtime errors resulting from implementations with mismatched this types.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Valutazione
Questa issue non è ancora stata valutata.