-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
keyof interface that extends dynamic key interface does not return keys #38664
Comments
This is working as intended. |
Ok, I understand. Thank you! Is there a way to only access |
That was the hint I missed out. I found a comment in another issue that solves my problem. Thank you! I really appreciate your support! |
I guess you're asking for something like "the keys of Teasing apart the keys of an object type with an index signature is possible but of dubious usefulness. You could. for example, use this method to get the literal/"known" keys of an object site: type KnownKeys<T> = {
[K in keyof T]: string extends K ? never : number extends K ? never : K
} extends { [_ in keyof T]: infer U } ? U : never; And then const bKey: KnownKeys<B> = "foo"; // error! But what is the goal here? If you really need to keep track of "the part of interface A {
[key: string]: number;
}
interface BminusA {
a: number;
}
interface B extends A, BminusA { } |
I implement a module system where I modules have dependencies. I need the types of the dependencies but I also need to check if all dependencies are passed in runtime. Therefore I need an array of the dependency keys. The following is a pseudo code explanation of what I need. interface Module<
ConcreteModuleDependencies extends ModuleDependencies = ModuleDependencies
> {
dependencies: KnownKeys<ConcreteModuleDependencies>;
defaultDependencies: Partial<ConcreteModuleDependencies>;
}
interface ModuleDependencies {
[key: string]: Module
}
interface FooModuleDependencies extends ModuleDependencies {
bar: BarModule
}
type FooModule = Module<FooModuleDependencies>;
const fooModule: FooModule = {
dependencies: ['bar'],
defaultDependencies: {
bar: BarModule
}
} |
What's |
You already answered my question. Thank you! |
TypeScript Version: Nightly
Search Terms:
keyof dynamic keys, keyof extended dynamic interface, keyof generic interface
Expected behavior:
bKey
should have"a"
as type.Actual behavior:
bKey
hasstring | number
as type.Related Issues:
14359
Code
Output
Compiler Options
Playground Link: Provided
The text was updated successfully, but these errors were encountered: