Skip to content

fix: widen optional properties for exactOptionalPropertyTypes compati… - #68

Open
maheshsingh20 wants to merge 1 commit into
cordiverse:mainfrom
maheshsingh20:fix/exact-optional-property-types
Open

fix: widen optional properties for exactOptionalPropertyTypes compati…#68
maheshsingh20 wants to merge 1 commit into
cordiverse:mainfrom
maheshsingh20:fix/exact-optional-property-types

Conversation

@maheshsingh20

Copy link
Copy Markdown

fix: widen optional properties for exactOptionalPropertyTypes compatibility

Summary

Fixes #65

Under TypeScript's exactOptionalPropertyTypes compiler flag, assigning undefined to an optional property whose declared type does not explicitly include undefined is a type error:

Type 'undefined' is not assignable to type 'Timeout'.

This is a type-only change — no runtime behavior is affected.

Changes

File Property Before After
packages/include/src/index.ts writeTask NodeJS.Timeout NodeJS.Timeout | undefined
packages/loader/src/config/entry.ts _initTask Promise<void> Promise<void> | undefined
packages/core/src/context.ts baseUrl string string | undefined

Details

All three properties are already marked optional (?) and are explicitly assigned undefined at various points in the codebase — so widening the type to include undefined is both correct and consistent.

While the original issue only reported writeTask in plugin-include, the same pattern was present in plugin-loader (_initTask) and core (baseUrl). All three are fixed here for consistency.

Consumer projects using "exactOptionalPropertyTypes": true in their tsconfig.json will 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 exactOptionalPropertyTypes is not enabled there. Consumer projects with the flag enabled will see the type errors resolved.

…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
@maheshsingh20

Copy link
Copy Markdown
Author

Apologies, closed this PR by mistake and reopened right away. PR is ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[plugin-include] writeTask?: NodeJS.Timeout rejects = undefined under exactOptionalPropertyTypes

1 participant