question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:open
  • Created 7 years ago
  • Reactions:42
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
jcalzcommented, Aug 31, 2017

I just ran into a problem where the obvious solution would be that methods without an explicit this parameter default it to the this 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 👍 ).

4reactions
tejasmanoharcommented, Nov 21, 2018

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 like cannot access property someClassFunction of undefined, I just change the declaration syntax to ES7 function bind syntax class 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found