Easy-peasy: Problem with union types properties when Typescript has "strict" compilerOptions to true

Created on 4 Feb 2019  路  4Comments  路  Source: ctrlplusb/easy-peasy

Having the strict: true compiler option in tsconfig.json creates an error for union types with null

image
image

My files

// tsconfig.json
{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "strict": true,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "baseUrl": ".",
    "jsx": "react"
  }
}
// index.tsx
import React from "react";
import { render } from "react-dom";
import { Action, createStore } from "easy-peasy";

interface CartModel {
  products?: string[] | null;
  setProducts: Action<CartModel, string[] | null>;
}

interface Model {
  cart: CartModel;
}

const model: Model = {
  cart: {
    products: null,
    setProducts: (state, payload) => {
      state.products = payload;
    }
  }
};

const store = createStore<Model>(model);

const App = () => {
  return <h1>test</h1>;
};

render(<App />, document.getElementById("app"));

Codesandbox (have to download and run tsc to see the error): https://codesandbox.io/s/321ly1v241

Current workaround:
Set strictNullChecks to false

bug

Most helpful comment

Have a solution! Just tidying up 馃憤

All 4 comments

This _could_ be an issue with Typescript (don't hold me to that). Needs more thorough investigation.

I've done some more investigation and can confirm this is an issue with easy-peasy. Working to resolve. 馃憤

Have a solution! Just tidying up 馃憤

Wow, this actually exposed some bad assumptions by myself, my new types I am working on are way way way better. No more {} & {} & {}...

Was this page helpful?
0 / 5 - 0 ratings