Skip to content
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

Closed
wants to merge 3 commits into from
Closed

default v2 #11

wants to merge 3 commits into from

Conversation

davidmdm
Copy link
Owner

No description provided.

@davidmdm davidmdm requested a review from pierreis April 27, 2020 15:53
assert.ok((schema as any)[coercionTypeSymbol]);
});

it('should return nested defaults with default object', () => {
Copy link
Owner Author

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;
Copy link
Owner Author

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?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

@pierreis pierreis Apr 27, 2020

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.

Copy link
Owner Author

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)

Copy link
Collaborator

@pierreis pierreis Apr 27, 2020

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.

Copy link
Owner Author

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...

Copy link
Owner Author

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

Copy link
Collaborator

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.

Copy link
Owner Author

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.

@davidmdm davidmdm closed this May 1, 2020
@davidmdm davidmdm deleted the default-v2 branch January 27, 2021 22:01
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.

None yet

2 participants