Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Docs: Mention about strictNullChecks in tsconfig.json #32

Open
khoinguyen opened this issue Apr 29, 2022 · 3 comments
Open

Improve Docs: Mention about strictNullChecks in tsconfig.json #32

khoinguyen opened this issue Apr 29, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@khoinguyen
Copy link

🚀 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
Copy link
Author

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

@anthonyjoeseph
Copy link
Owner

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 anthonyjoeseph added the enhancement New feature or request label Apr 29, 2022
@anthonyjoeseph
Copy link
Owner

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

type StrictNullChecksEnabled = IsNull<undefined>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants