Skip to content

Exact Optional Property Types in TypeScript 4.4 #444

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

Closed
nelsonni opened this issue Jun 24, 2021 · 2 comments
Closed

Exact Optional Property Types in TypeScript 4.4 #444

nelsonni opened this issue Jun 24, 2021 · 2 comments
Assignees
Labels
bug Bug reports or bug fixes dependencies Issues or updates to dependency files
Milestone

Comments

@nelsonni
Copy link
Member

nelsonni commented Jun 24, 2021

Describe the bug
Exact optional property types restrict the type of optional properties (e.g. foo?: string) to either be defined or not, but not equivalent to | undefined (as was the previous behavior); per microsoft/TypeScript#43947. This causes errors with several optional properties defined in types.d.ts, since there are several points at which properties are set assuming that undefined is synonymous with optional (e.g. prop? => string | undefined).

To Reproduce
Steps to reproduce the behavior:

  1. Update to typescript >= 4.4
  2. Go to modals.ts.
  3. See TS highlighted type errors for subtype, target, and options, which indicate:
Type 'string | undefined' is not assignable to type 'string'.
  Type 'undefined' is not assignable to type 'string'.ts(2322)
types.d.ts(180, 12): The expected type comes from property 'subtype' which is declared here on type 'Modal'
(property) subtype?: string

Expected behavior
Allow optional properties to be synonymous with undefined (e.g. const bar?: string => string | undefined).

Screenshots
image

Versions (please complete the following information):

  • OS: MacOS, Windows, Linux
  • Synectic Version: 1.0.0-beta (branch: development)

Additional context
Additional discussion regarding the impact of this breaking change can be found at microsoft/TypeScript#44421.

@nelsonni nelsonni added the bug Bug reports or bug fixes label Jun 24, 2021
@nelsonni nelsonni added this to the v1.0.0 milestone Jun 24, 2021
@nelsonni nelsonni self-assigned this Jun 24, 2021
@nelsonni nelsonni added the dependencies Issues or updates to dependency files label Jun 30, 2021
@nelsonni nelsonni changed the title Strict optional properties in TypeScript 4.4.0 Exact Optional Property Types in TypeScript 4.4 Jul 7, 2021
@nelsonni
Copy link
Member Author

nelsonni commented Jul 30, 2021

TSConfig provides an exactOptionalPropertyTypes option that can be set in tsconfig.json files to enforce Exact Optional Property Types (introduced in TypeScript 4.4) using the TypeScript type-checker. Additionally, the exactOptionalPropertyTypes requires that strictNullChecks also be enabled in TSConfig.

@nelsonni
Copy link
Member Author

Synectic has been updated to TypeScript 4.4, along with enabling the exactOptionalPropertyTypes option, in commits aec6164...b24ece4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug reports or bug fixes dependencies Issues or updates to dependency files
Projects
None yet
Development

No branches or pull requests

1 participant