Typescript: Imperfect error message for invoking null literal as function

Created on 15 Nov 2017  路  3Comments  路  Source: microsoft/TypeScript




TypeScript Version: 2.6.1

Code

Minimal:

null()

Actual real-world mistake:

str !== 'hello' && thing !== null (
  <div>blah</div>
)

Expected behavior:

Clear error to the effect of:

Invoking 'null' as a function

Actual behavior:

Technically correct but slightly misleading error:

Object is possibly 'null'

Bug Error Messages Fixed good first issue help wanted

Most helpful comment

thanks @remojansen!

All 3 comments

To be consistent, reasonable error message text would be something to the effect of

Cannot invoke an object which is possibly 'null'.
Cannot invoke an object which is possibly 'undefined'.
Cannot invoke an object which is possibly 'null' or 'undefined'.

I have sent a PR (#20157) for this issue. I was able to pass all the tests locally. I'm hoping that there will be no issues in CI. Please let me know if anything is wrong (This is my first PR for the TS compiler :tada:).

thanks @remojansen!

Was this page helpful?
0 / 5 - 0 ratings