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

Exact does not work with Opaque after 2.19.0 #508

Closed
eugene-mohc opened this issue Nov 8, 2022 · 5 comments · Fixed by #525
Closed

Exact does not work with Opaque after 2.19.0 #508

eugene-mohc opened this issue Nov 8, 2022 · 5 comments · Fixed by #525

Comments

@eugene-mohc
Copy link

eugene-mohc commented Nov 8, 2022

Exact no longer works when there are any object properties which have a type created using Opaque. This used to work using version 2.18.0 and lower.

type SpecialName = Opaque<string, "special name">;

type OnlyAcceptName = {
  name: SpecialName;
};

function onlyAcceptNameImproved<T extends Exact<OnlyAcceptName, T>>(args: T) {}

onlyAcceptNameImproved({
  // Error: Type 'SpecialName' is not assignable to type 'never'
  name: "name" as SpecialName
});

Example using type-fest 2.18.0: https://codesandbox.io/s/twilight-shape-bc391p?file=/src/index.ts

Same example using latest version: https://codesandbox.io/s/boring-morse-96egn3?file=/src/index.ts

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • The funding will be given to active contributors.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@sindresorhus
Copy link
Owner

Most likely this change: edcad04

@sindresorhus
Copy link
Owner

// @zorji

@zorji
Copy link
Contributor

zorji commented Nov 30, 2022

Sorry for the late reply. Let me have a look.

@zorji
Copy link
Contributor

zorji commented Nov 30, 2022

Hi @eugene-mohc

Sorry I am not familiar with Opaque type and what's its use case but looks like it's trying to solve a similar issue that this Exact type was trying to solve. By reading the definition of Opaque type, I am not sure whether it's because the internal details are hidden so it's not accessible and compare.

I am wondering whether the solution to check if it's an Opaque type and return the type as it is can solve the issue.

Would you able to checkout the change in this branch and see if that fixes the issue for you? #525

@eugene-mohc
Copy link
Author

Hi and thank you, that has solved it for my use cases. I was only using Opaque with strings and numbers though, so I can't comment on how it would work with any others.

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 a pull request may close this issue.

3 participants