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

Mark TypeScript types as non-nullable #259

Merged
merged 4 commits into from
Nov 11, 2016
Merged

Mark TypeScript types as non-nullable #259

merged 4 commits into from
Nov 11, 2016

Conversation

mprobst
Copy link
Contributor

@mprobst mprobst commented Nov 11, 2016

Required some more yaks to loose their fur.

Note that the support for NonNullable expressions is very flakey, due to microsoft/TypeScript#9873, just as it was for casts before.

@mprobst
Copy link
Contributor Author

mprobst commented Nov 11, 2016

/CC @dpurp

All tsickle users (AFAIK) use strict null checks, and enabling these is required to properly test our nullable types conversion.
All TypeScript types in strictNullChecks mode are non-nullable, where Closure types without a ! are treated as nullable. This change adds ! on all types except for types treated as never null primitives by Closure Compiler (number, string, function).

let /** @type {(string|boolean)} */ typeUnion: string|boolean = Math.random() > 0.5 ? false : '';
let /** @type {(string|boolean)} */ typeUnion2: (string|boolean) = Math.random() > 0.5 ? false : '';
let /** @type {{optional: (boolean|undefined)}} */ typeOptionalField: {optional?: boolean} = {};
let /** @type {{optional: ((string|boolean)|undefined)}} */ typeOptionalUnion: {optional?: string|boolean} = {};
let /** @type {{optional: ((undefined|boolean)|undefined)}} */ typeOptionalField: {optional?: boolean} = {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to collapse the two undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, done (and simplifies the code!).

… by TypeScript including |undefined in a union type in strictNullChecks mode.
@mprobst mprobst merged commit 778e9e5 into master Nov 11, 2016
@mprobst mprobst deleted the simpler-null branch November 11, 2016 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants