mobx-state-tree icon indicating copy to clipboard operation
mobx-state-tree copied to clipboard

strictNullChecks: false does not get along well with types.optional in Typescript

Open marcofugaro opened this issue 6 years ago • 2 comments

Bug report

  • [x] I've checked documentation and searched for existing issues
  • [x] I've made sure my project is based on the latest MST version
  • [x] Fork this code sandbox or another minimal reproduction.

Sandbox link or minimal reproduction code https://codesandbox.io/s/zn8262jl0l

Describe the expected behavior There should be no errors in typescript

Describe the observed behavior This not helpful error appears image

This happens since version v3.11.0 where the optional type was revisited adding a third argument.

However typescript gets angry when that default [undefined] value is not explicitly specified, making your life impossible when using primitive types (which are syntactic sugar to t.optional).

E.g. isModalOpen: false in a model.

This is probably related to #1208

marcofugaro avatar May 14 '19 09:05 marcofugaro

Could you post your tsconfig.json? Do you have strict null checks disabled by any chance?

xaviergonz avatar May 14 '19 18:05 xaviergonz

Yes, this is my tsconfig.json, I have strict null checks disabled, however I don't think MST must depend on my personal typescript configuration.

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["esnext", "dom", "dom.iterable"],
    "module": "esnext",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "sourceMap": true,
    "jsx": "react",
    "strict": true,
    "strictNullChecks": false,
    "noImplicitReturns": true,
    "suppressImplicitAnyIndexErrors": true,
    "noUnusedLocals": false,
    "forceConsistentCasingInFileNames": true,
    "experimentalDecorators": true
  },
  "include": ["src"]
}

marcofugaro avatar May 15 '19 09:05 marcofugaro

I'm no longer able to reproduce (on master).

CleanShot 2024-07-07 at 13 28 08@2x

Let me know if you're still experiencing an issue. Otherwise, we'll close this one out :)

thegedge avatar Jul 07 '24 17:07 thegedge

Yup, looks like the reproduction Sandbox has it resolved on mobx-state-tree@latest: https://codesandbox.io/p/sandbox/zn8262jl0l?file=%2FState.tsx%3A7%2C4.

Closin' out. Thanks for the follow up on this @thegedge, and sorry to everyone else that it took a while to fix and close.

coolsoftwaretyler avatar Jul 07 '24 19:07 coolsoftwaretyler