blueprint icon indicating copy to clipboard operation
blueprint copied to clipboard

Enable strictNullChecks compiler option for all packages

Open giladgray opened this issue 8 years ago • 9 comments

I think enabling strictNullChecks compiler option for datetime package will help us detect and prevent a whole host of potential errors, such as #322. it'll also address #274 by making the typings more accurate (as explicit null Dates actually means something in the component).

giladgray avatar Dec 06 '16 23:12 giladgray

I think the compiler option should be enabled for all packages. Updating issue title to reflect this.

adidahiya avatar Dec 07 '16 01:12 adidahiya

Fair enough! Converting core will take some time due to its sheer size, hence why I started with datetime. Any idea if this will affect typings in a breaking way?

giladgray avatar Dec 07 '16 02:12 giladgray

No, any changes in the generated .d.ts files ought to be tractable & compatible with consumers' tsc versions. If anything, it will expose bugs in consuming applications (not handling null / undefined values).

adidahiya avatar Dec 07 '16 03:12 adidahiya

in my ideal world, we also enable the no-null-keyword lint rule and any explicit usage of null would have to be whitelisted

https://github.com/palantir/blueprint/pull/419#discussion_r94995122

giladgray avatar Jan 06 '17 19:01 giladgray

started working on this and quickly ran into some heavy sadness with setState:

  • https://github.com/Microsoft/TypeScript/issues/6613
  • https://github.com/Microsoft/TypeScript/issues/12793

basically, this.state fields should all be required (otherwise you have to cast/check before using any as they're all X | undefined), but then we can't setState() with partial objects. the solution is Pick and @ericanderson has submitted a PR to DT to update react typings accordingly: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/13155 (blocked on this).

giladgray avatar Jan 17 '17 17:01 giladgray

Cool, it looks like that PR will be merged in DefinitelyTyped soon enough and I don't mind blocking on it.

adidahiya avatar Jan 17 '17 18:01 adidahiya

We're good to go on the setState enhancements in the React typings now. Pull the latest @types/react.

adidahiya avatar Jan 26 '17 02:01 adidahiya

If we forbid using null, what's the best way to indicate an empty value for controlled input components. Using undefined doesn't work because that indicates that the component should be in uncontrolled mode. Some inputs have a logical empty value - like for text inputs, the empty value should be represented as "". But, what about for something less clear - like a date input. Should we export an explicit empty value to use in that case? Looks like we do something that here https://github.com/palantir/blueprint/blob/45c07c597c716655a028f092e9966cc65b54b15f/packages/core/src/components/forms/numericInput.tsx

brieb avatar Sep 15 '17 04:09 brieb

(updated your link to be a permalink)

Should we export an explicit empty value to use in that case?

yeah, this sounds reasonable to me. I would be curious to see how far we can get with avoiding null in our public API.

adidahiya avatar Sep 18 '17 17:09 adidahiya