Skip to content

fix: allow undefined in isOptional and allowNull under exactOptionalPropertyTypes - #157

Open
OscarMasse wants to merge 1 commit into
vinejs:4.xfrom
OscarMasse:fix/exact-optional-property-types
Open

OscarMasse wants to merge 1 commit into
vinejs:4.xfrom
OscarMasse:fix/exact-optional-property-types

Conversation

@OscarMasse

Copy link
Copy Markdown

Fixes #141.

Problem

With exactOptionalPropertyTypes: true in the consumer's tsconfig, every optional or nullable field fails the SchemaTypes constraint:

TS2375: Type 'OptionalModifier<VineString>' is not assignable to type 'SchemaTypes' with 'exactOptionalPropertyTypes: true'.

ConstructableSchema and ConstructableLiteralSchema declare isOptional?: boolean and allowNull?: boolean, while the modifiers forward their parent's value through getters typed boolean | undefined (for example get allowNull() { return this.#parent.allowNull }).
Under the flag, ?: boolean no longer accepts a present-but-undefined value, so the modifiers stop satisfying the interface they implement, and Infer<typeof schema> degrades to { [x: string]: any }.
This is the diagnosis @TomBeckett posted on the issue.

Fix

Widen both properties to boolean | undefined in 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.
  • A real application's validators (a few dozen vine.compile(vine.object(...)) schemas with optional and nullable fields), compiled with exactOptionalPropertyTypes: true and skipLibCheck: true: 116 errors against 4.4.0 (111 on allowNull, 5 on isOptional), 0 with this change.

@OscarMasse
OscarMasse changed the base branch from develop to 4.x September 25, 2026 09:29
@OscarMasse

Copy link
Copy Markdown
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 4.x after #158. Happy to adjust anything. Thanks!

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.

Typescript Error On Optional And Nullable Fields With exactOptionalPropertyTypes

1 participant