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.

Enable "strictNullChecks" option for TS definitions

See original GitHub issue

A clean version of joint 2.1.0, obtained by running npm i jointjs, results in the following TypeScript errors: (2062,38): Type 'undefined' does not satisfy the constraint 'Model'. (2092,38): Type 'undefined' does not satisfy the constraint 'Model'.

Replacing mvc.View<undefined> by mvc.View<Backbone.Model> seems to fix it, but I can imagine undefined being a more concrete implementation of Backbone.Model. How should I fix this?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
zuozhiwcommented, Jun 5, 2018

@swenmeeuwes In tsconfig.json, you can set "skipLibCheck": true to let Typescript skip checking the libraries in strict mode, and you can add back "strictNullChecks": true, or maybe even "strict": true.

One suggestion to JointJS Typescript declarations regarding strictNullChecks in Typescript. Some of the type declarations are not strict. For example: getCell(id: string | number | Cell): Cell; But when the id doesn’t exist, this function returns undefined, so it’s better to write getCell(id: string | number | Cell): Cell | undefined;

3reactions
swenmeeuwescommented, May 8, 2018

Hi vtalas,

First I stripped down my project to only use TypeScript en JointJs. After still getting the error I compared my project with the demo project and spotted a difference in tsconfig.json.

This line was the villain: "strictNullChecks": true,

Setting it to ‘false’ fixed the issue. Although I’d rather leave this setting on for code safety reasons.

Is there going to be support for this in the future? To reproduce you can just use the ts-demo and add "strictNullChecks": true to the tsconfig.json.

Read more comments on GitHub >

github_iconTop Results From Across the Web

strictNullChecks - TSConfig Option
When strictNullChecks is false , null and undefined are effectively ignored by the language. This can lead to unexpected errors at runtime.
Read more >
StrictNullChecks in TypeScript - Best Practice
The 'strictNullChecks' TypeScript compiler option allow you to catch null pointers at compile time, providing you with extra safety for your application.
Read more >
Typescript strictNullChecks with limited scope
It's a global setting that changes how all interpretations of types behave. There's not even a coherent definition of what it would mean...
Read more >
TypeScript "strictNullChecks" - a migration guide
Enabling this option effectively narrows the set of possible types for every variable, which means that the editor can infer more about the ......
Read more >
Writing safer code with TypeScript strict null checks & type ...
Uncaught ReferenceError: foo is not defined Uncaught TypeError: ... It can be enabled by adding the –strictNullChecks flag as an option to ...
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