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: add support for ts satisfies operator #156

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

DavideSegullo
Copy link
Contributor

This PR add support for the satisfies operator of typescript; the intent is to provide more versatile data types for library creators. Using this operator we can validate that a data type meets a specific interface, but at the same time we can also make it readonly, which allows us to be able to dynamically derive chain names and be able to create auto-suggest systems, example:

import { chain as chain_cosmoshub } from 'chain-registry/mainnet/cosmoshub';
import { chain as chain_osmosis } from 'chain-registry/mainnet/osmosis';

const supportedChains = [
  chain_osmosis,
  chain_cosmoshub,
];

export type Chains = typeof supportedChains[number]['chain_name']
//          ^ output: "osmosis" | "cosmoshub"

It's also the same approach used for example by wagmi and viem.

Why?

When developing in TS, one is often faced with the dilemma of wanting to validate a data type but without altering its structure for inference purposes.

From TS Doc:

The new satisfies operator lets us validate that the type of an expression matches some type, without changing the resulting type of that expression.

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