New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
default v2 #11
default v2 #11
Conversation
assert.ok((schema as any)[coercionTypeSymbol]); | ||
}); | ||
|
||
it('should return nested defaults with default object', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this test which is the use case we wanted. However I can't get the typing to work
src/types.ts
Outdated
|
||
type DS = DefaultableType<StringType>; | ||
|
||
type R = DS extends Type<any> ? (DS extends Type<infer K> ? K : DS) : any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't seem to be able to infer the type of of a DefaultableType (substitute StringType for any other Type class)... It just goes to any... any insight?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure.
That is quite disturbing indeed.
Let me check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I managed to get type Infer to worth with DefaultTypes by making Infer more exhaustive:
export type Infer<T extends AnyType> = T extends DefaultableType<any>
? T extends DefaultableType<infer Schema>
? Schema extends Type<infer K>
? Eval<K>
: never
: never
: T extends Type<infer K>
? Eval<K>
: never;
But I still can't get the DefaultType<ObjectType> to type the correct defaultValue (default keys as optional)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. Debugging advanced types in TypeScript is hellish...
I still have no clue.
Regardless, it is extremely strange to see inference working for Optional
but not for Defaultable
, considering that the two are defined almost identically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've managed to get very close. However I now have the DeepPartialShape type become possibly infinitely deep, it keeps doing that sometimes when something gets more complicated in the type system.
I find that typescript is extremely buggy once you go a little advanced... I'll keep at it for a while... But although we've managed to introduce DefaultableType I still can't type the keys of defaultValue of object as optional... Losing my mind haha...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am considering throwing away deepPartial... It has been a thorn in my side getting it to keep compiling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot really see a use-case from my point of view, so I wouldn't mind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed with everything working except for the fact that deepPartialShape will no longer compile. Gonna sit on this for a little as I mull it over.
No description provided.