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

Remove index signature #163

Open
aspirisen opened this issue Feb 11, 2021 · 0 comments
Open

Remove index signature #163

aspirisen opened this issue Feb 11, 2021 · 0 comments

Comments

@aspirisen
Copy link

Is your feature request related to a real problem or use-case?

Remove index signature from T. Some libraries return type with index signatures. For example in yargs

const yargsSchema = yargs(process.argv.slice(2)).options({
  MY: { type: 'string', default: 'SOME' },
})

yargsSchema.argv['MY'] // Ok, and have autocomplete for this property
yargsSchema.argv['UNKNOWN'] // This property doesn't exist, but I still can access it without errors

Describe a solution including usage in code example

There is a proposed solution on StackOverflow https://stackoverflow.com/a/51956054/3021445
Would be nice to have this here as well in utility-types

type KnownKeys<T> = {
  [K in keyof T]: string extends K ? never : number extends K ? never : K
} extends { [_ in keyof T]: infer U } ? U : never;

type FooWithOnlyBar = Pick<Foo, KnownKeys<Foo>>;

Who does this impact? Who is this for?

All TypeScript users

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

No branches or pull requests

1 participant