You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When migrating from S.optional(...).withDefault(...), we hit an issue with S.literal. This hasn't been an issue for us with any other types.
This example code block throws a type error on the default property.
constFooSchema=S.literal('a','b','c');constMySchema=S.struct({foo: S.optional(FooSchema,{default: ()=>'a',// Object literal may only specify known properties, and// 'default' does not exist in type '{ readonly as: "Option"; }'.}),});
The full error is:
No overload matches this call.
The last overload gave the following error.
Object literal may only specify known properties, and 'default' does not exist in type '{ readonly as: "Option"; }'.ts(2769)
We can work around the issue by setting the types as below:
TypeScript errors are a bit cryptic when it comes to overloads (the overload with as: "Option" is only the last one attempted by the type checker), here the actual problem is the default parameter being inferred as string instead of "a", to resolve this you can add as const:
What version of Effect is running?
2.2.2
What steps can reproduce the bug?
When migrating from
S.optional(...).withDefault(...)
, we hit an issue withS.literal
. This hasn't been an issue for us with any other types.This example code block throws a type error on the
default
property.The full error is:
We can work around the issue by setting the types as below:
What is the expected behavior?
When using
S.literal
withS.optional
,as: "Option"
should not be automatically applied.What do you see instead?
The error shows that
as: "Option"
is being automatically applied.Additional information
TypeScript 5.3.3.
The text was updated successfully, but these errors were encountered: