Flag for strict default function `this` types for call-site and assignability checking (`--strictThis`)
See original GitHub issue#6018 was originally going to add a --strictThis
flag that made function this
types default to void
or the enclosing class (instead of any
) for purposes of call-site and assignability checking, but that functionality was dropped (details). This is a follow-up suggestion for the dropped functionality, whatever the flag ends up being named.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:42
- Comments:6 (2 by maintainers)
Top Results From Across the Web
g++(1) - Linux manual page - man7.org
This flag is enabled by default unless -fabi-version=10 or lower is specified. ... types is by using the appropriate constructor or assignment operator, ......
Read more >this - JavaScript | MDN
A function's this keyword behaves a little differently in JavaScript ... In non–strict mode, this is always a reference to an object.
Read more >Mypy Documentation - Read the Docs
Mypy is a static type checker for Python. Type checkers help ensure that you're using variables and functions in your code correctly.
Read more >Glasgow Haskell Compiler 8.4.1 User's Guide
Strict, Make bindings in the current module strict by default. ... is equivalent (from the point of view of both type checking and...
Read more >Ubuntu Manpage: gcc - GNU project C and C++ compiler
If neither flag is given, the default is to follow the standard, ... guesses that function pointers with "format" attributes that are used...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I just ran into a problem where the obvious solution would be that methods without an explicit
this
parameter default it to thethis
type. Searching brought me here. So the main problem is… performance? In any case, I hope a--strictThis
option makes it into TS sometime (adding my 👍 ).I also hope this is added back. I just started using Typescript last week, and this is basically the only “type error” I’ve run into (and repeatedly for that matter) in my all Typescript codebase. I hit it frequently, as I am using an ES6 classes as a router/controller in my Express app, e.g.
app.use(this.someClassFunction)
. When I see failing tests with an error likecannot access property someClassFunction of undefined
, I just change the declaration syntax to ES7 function bind syntaxclass X { constructor() {} x: (req, res) => {} }
and the issue is fixed, but it would be really nice to know about that at compile time instead of at runtime.I’ve been impressed with Typescript in general but was very surprised to hear that it’s not checked at compile time since I can’t think of another typed language, where such an error is possible.