fix: widen optional properties for exactOptionalPropertyTypes compati… - #68
Open
maheshsingh20 wants to merge 1 commit into
Open
fix: widen optional properties for exactOptionalPropertyTypes compati…#68maheshsingh20 wants to merge 1 commit into
maheshsingh20 wants to merge 1 commit into
Conversation
…bility Under TypeScript's exactOptionalPropertyTypes flag, assigning undefined to an optional property whose declared type does not include undefined is a type error. Widen the following declarations (type-only, no behavior change): - packages/include/src/index.ts: writeTask?: NodeJS.Timeout | undefined - packages/loader/src/config/entry.ts: _initTask?: Promise<void> | undefined - packages/core/src/context.ts: baseUrl?: string | undefined Fixes cordiverse#65
Author
|
Apologies, closed this PR by mistake and reopened right away. PR is ready for review. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: widen optional properties for exactOptionalPropertyTypes compatibility
Summary
Fixes #65
Under TypeScript's
exactOptionalPropertyTypescompiler flag, assigningundefinedto an optional property whose declared type does not explicitly includeundefinedis a type error:This is a type-only change — no runtime behavior is affected.
Changes
packages/include/src/index.tswriteTaskNodeJS.TimeoutNodeJS.Timeout | undefinedpackages/loader/src/config/entry.ts_initTaskPromise<void>Promise<void> | undefinedpackages/core/src/context.tsbaseUrlstringstring | undefinedDetails
All three properties are already marked optional (
?) and are explicitly assignedundefinedat various points in the codebase — so widening the type to includeundefinedis both correct and consistent.While the original issue only reported
writeTaskinplugin-include, the same pattern was present inplugin-loader(_initTask) andcore(baseUrl). All three are fixed here for consistency.Consumer projects using
"exactOptionalPropertyTypes": truein theirtsconfig.jsonwill no longer hit type errors when importing these packages.Testing
No behavior change — this is purely a type annotation fix. The upstream build is unaffected since
exactOptionalPropertyTypesis not enabled there. Consumer projects with the flag enabled will see the type errors resolved.