How to get properties of {[key in keyof T]: T[key]} type?
See original GitHub issueimport { getType, Type } from "tst-reflect"
export class Temp {
id: string
email: string
}
type T = {
[key in keyof Temp]: Temp[key]
}
function foo<T>() {
const type: Type = getType<T>()
console.log(type)
}
foo<T>()
Following code produces
this output
TypeActivator {
_name: 'T',
_fullName: 'T',
_kind: 5,
_constructors: [],
_properties: [],
_methods: [],
_decorators: [],
_typeParameters: [],
_ctor: undefined,
_ctorDesc: ConstructorImportActivator {},
_interface: undefined,
_isUnion: false,
_isIntersection: false,
_types: [],
_literalValue: undefined,
_typeArgs: [],
_conditionalType: undefined,
_indexedAccessType: undefined,
_genericTypeConstraint: undefined,
_genericTypeDefault: undefined,
_baseType: TypeActivator {
_name: 'Object',
_fullName: 'Object',
_kind: 2,
_constructors: [],
_properties: [],
_methods: [],
_decorators: [],
_typeParameters: [],
_ctor: [Function: ctor],
_ctorDesc: ConstructorImportActivator {},
_interface: undefined,
_isUnion: false,
_isIntersection: false,
_types: [],
_literalValue: undefined,
_typeArgs: [],
_conditionalType: undefined,
_indexedAccessType: undefined,
_genericTypeConstraint: undefined,
_genericTypeDefault: undefined,
_baseType: undefined
}
}
Does it work with Omit
and Pick
? (I see the same output for them because they are implemented in similar way I did it in example)
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
How to use the keyof operator in TypeScript - LogRocket Blog
In JavaScript, we often use Object.keys to get a list of property keys. ... keyof T returns a union of string literal types....
Read more >Typescript using get<T>(key: keyof T) - Stack Overflow
To be able to infer property type based on provided key we need to introduce generic type parameter for key. Currently partial type...
Read more >Documentation - TypeScript 2.1
Enter Index Type Query or keyof ; An indexed type query keyof T yields the type of permitted property names for T ....
Read more >Help getting type of key of generic : r/typescript - Reddit
Here's what I'm trying to accomplish type MyType = { a: string, b: number } interface PatchOperation { property: keyof T, ...
Read more >Advanced uses of Typescript type system 01 - From mapped ...
What they don't allow is having generic property names. ... A way to get keyof only for certain types of keys type KeyofMethods<TType>...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ah yeah, I see. Didn’t notice that typescript throws it away in indexer (anyway, I don’t use these indexers now, it was added for migrating)
Thanks for making this amazing package, really appreciate the effort!
Works like a charm!
Only bug I found during some testing, that
Omit
fails when using[key: string]: any
extension in class:Example output
If marked line is uncommented, then type is wrong, otherwise $-$ works as intended