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

Treat struct properties that have type undefined as optional #639

Closed

Conversation

thewilkybarkid
Copy link
Contributor

This is an attempt to fix #628 (comment), by making properties in a struct that can have undefined as a value optional.

This feels quite thorny to do, and this is probably incomplete (e.g. Schemeable?).

Comment on lines +397 to +398
type Identity<T> = T
type Merge<T> = T extends any ? Identity<{ [k in keyof T]: T[k] }> : never
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines +393 to +396
type UndefinedProperties<T> = {
[P in keyof T]-?: undefined extends T[P] ? P : never
}[keyof T]
type ToOptional<T> = Merge<Pick<T, Exclude<keyof T, UndefinedProperties<T>>> & Partial<Pick<T, UndefinedProperties<T>>>>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines -112 to +130
// $ExpectType Codec<unknown, { _tag: "A"; a: string; } | { _tag: "B"; b: number; }, { _tag: "A"; a: string; } | { _tag: "B"; b: number; }>
// $ExpectType Codec<unknown, { a: string; _tag: "A"; } | { b: number; _tag: "B"; }, { a: string; _tag: "A"; } | { b: number; _tag: "B"; }>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wasn't expecting these to be reordered.

@thewilkybarkid
Copy link
Contributor Author

I'm going to close this in favour of gcanti/fp-ts#1693.

@thewilkybarkid thewilkybarkid deleted the optional-undefined branch April 6, 2022 12:51
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.

1 participant