Repository navigation
fix: allow undefined in isOptional and allowNull under exactOptionalPropertyTypes - #157
Open
OscarMasse wants to merge 1 commit into
Open
OscarMasse wants to merge 1 commit into
OscarMasse wants to merge 1 commit into
Conversation
Author
|
Hi! Friendly ping on this one. The CI workflows are waiting for maintainer approval (first-time contributor), so nothing has run yet. The change is types-only and still merges cleanly on |
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.
Fixes #141.
Problem
With
exactOptionalPropertyTypes: truein the consumer's tsconfig, every optional or nullable field fails theSchemaTypesconstraint:ConstructableSchemaandConstructableLiteralSchemadeclareisOptional?: booleanandallowNull?: boolean, while the modifiers forward their parent's value through getters typedboolean | undefined(for exampleget allowNull() { return this.#parent.allowNull }).Under the flag,
?: booleanno longer accepts a present-but-undefinedvalue, so the modifiers stop satisfying the interface they implement, andInfer<typeof schema>degrades to{ [x: string]: any }.This is the diagnosis @TomBeckett posted on the issue.
Fix
Widen both properties to
boolean | undefinedin the two interfaces, which is what the getters actually return.Types only, no runtime change, and nothing changes for projects without the flag.
Verification
npm run typecheck, lint and the test suite pass as before.vine.compile(vine.object(...))schemas with optional and nullable fields), compiled withexactOptionalPropertyTypes: trueandskipLibCheck: true: 116 errors against 4.4.0 (111 onallowNull, 5 onisOptional), 0 with this change.