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

Use typed identity functions to guide type inference #25

Open
utterances-bot opened this issue Jan 25, 2023 · 1 comment
Open

Use typed identity functions to guide type inference #25

utterances-bot opened this issue Jan 25, 2023 · 1 comment
Labels
💬 blog comments Comments on effectivetypescript.com (Utterances)

Comments

@utterances-bot
Copy link

Use typed identity functions to guide type inference

Effective TypeScript: Use typed identity functions to guide type inference

https://effectivetypescript.com/2020/06/16/typed-identity-functions/

Copy link
Owner

danvk commented Jan 25, 2023

While the tuple helper still has its place, TypeScript 4.9's satisfies operator has made the last two examples obsolete.

Instead of withValueType<T>, you can use satisfies Record<string, T>:

const capitals = {
  ny: [-73.7562, 42.6526],
  ca: [-121.4944, 38.5816],
  ak: [-134.4197, 58.3019],
} satisfies Record<string, Point>;

Instead of withValueTypesFrom, you can use satisfies Partial<T>: This doesn't quite do the same thing!

Progress!

@danvk danvk added the 💬 blog comments Comments on effectivetypescript.com (Utterances) label Jan 25, 2023 — with utterances
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💬 blog comments Comments on effectivetypescript.com (Utterances)
Projects
None yet
Development

No branches or pull requests

2 participants