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

feat!: support generic type with unknown default #68

Merged
merged 2 commits into from Jun 12, 2023
Merged

feat!: support generic type with unknown default #68

merged 2 commits into from Jun 12, 2023

Conversation

pi0
Copy link
Member

@pi0 pi0 commented Jun 12, 2023

JSON.parse returns any type. This makes destr type safe by default and allow specify types using generics.

This feature will be available for destr>=2.0.0

Credits to @rijkvanzanten (unjs/h3#387) <3

@pi0 pi0 changed the title feat!: support generic type with unkown default feat!: support generic type with unknown default Jun 12, 2023
@pi0 pi0 merged commit d4e8634 into main Jun 12, 2023
1 check passed
@pi0 pi0 deleted the type/unkown branch June 12, 2023 11:28
pi0 added a commit that referenced this pull request Jun 12, 2023
@pi0 pi0 requested review from danielroe and removed request for danielroe June 12, 2023 12:00
@danielroe
Copy link
Member

beautiful 👌

@@ -27,37 +27,40 @@ export type Options = {
strict?: boolean;
};

export default function destr(value: any, options: Options = {}): any {
export default function destr<T = unknown>(
value: any,

Choose a reason for hiding this comment

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

Not to be extra difficult, but should this be an unknown as well to improve destr's own type safety? By treating the parameter as any, the type checking within this function block is effectively disabled 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

PR welcome to refactor 👍🏼

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

3 participants