spectacles-ts icon indicating copy to clipboard operation
spectacles-ts copied to clipboard

Improve Docs: Mention about `strictNullChecks` in tsconfig.json

Open khoinguyen opened this issue 3 years ago • 3 comments

🚀 Feature request

This is not really a Feature Request, I spent hours to figure out the issue, but I don't think it is a bug too.

Current Behavior

No where mentioned about the "strictNullChecks": true must be set in tsconfig.json in order to let spectacles-ts to work correctly.

When I try spectacles-ts on experimental site, it works well: https://codesandbox.io/s/spectacles-ts-experiments-krc1x9?file=/tsconfig.json

But I created my own simple project with npm init and copy an tsconfig.json from my existing project, with following index.ts:

import { pipe } from "fp-ts/lib/function";
import { get } from "spectacles-ts";

export type DbAddress = {
  address?: string;
  city?: string;
  state?: string;
  country?: string;
  lat?: number;
  lng?: number;
  postCode?: string;
};

export type DbUserAddress = {
  record: DbAddress;
  streetAddress: string;
};

const got = (uaddr: DbUserAddress) => pipe(uaddr, get("record"));
// IDE show: const got: (uaddr: DbUserAddress) => DbUserAddress

I use the same code in experimental site, it infer correctly: const got: (uaddr: DbUserAddress) => DbAddress

I tried to change the version of dependencies but not works Then I diff my tsconfig, and experimental tsconfig, remove/change this and that config.

After all, when I add strictNullChecks: true, it works like a charm.

Desired Behavior

Short description in the Installation about this.

Suggested Solution

Short description in the Installation about this.

Who does this impact? Who is this for?

Who have configure the tsconfig.json without strictNullChecks or set to false

Describe alternatives you've considered

Additional context

Your environment

Software Version(s)
spectacles-ts 1.0.6
fp-ts 2.11.9
TypeScript ^4.6.4

khoinguyen avatar Apr 29 '22 13:04 khoinguyen

After adding "strictNullChecks": true to my existing project, a lot of complaints about T | null (of course), which brings spectacles-ts almost not usable for me to migrate from lodash

khoinguyen avatar Apr 29 '22 14:04 khoinguyen

thanks for bringing this up, sorry this is an issue for you and your team. I'll make a change to the docs presently. I'll have to experiment and see if it's possible to support "strictNullChecks": false as well as true. It might be possible to detect that setting at the type-level and disable optional chaining if it's disabled

anthonyjoeseph avatar Apr 29 '22 21:04 anthonyjoeseph

looks like this is possible at the type level, using the IsNull predicate:

type StrictNullChecksEnabled = IsNull<undefined>

anthonyjoeseph avatar Apr 29 '22 21:04 anthonyjoeseph