4 ms·
Dumb question, is this expressed in TypeScript by the way it offers the ability to write logic inside types using keywords like `infer`, `extends`, `in`, etc?
by apatheticonion 5y ago
Dumb question, is this expressed in TypeScript by the way it offers the ability to write logic inside types using keywords like `infer`, `extends`, `in`, etc?
type Foo<T extends Record<any, any>> = {
[K in keyof T]: T[K]
}
- bmn__ 5y agoNot a dumb question. Answer is no, TS's features are in general not sufficient to express dependent types. It would need to stop making a distinction between types and values, and allow running arbitrary (total) functions in order to define a type, at the least. Experiment with a toy implementation: <https://thelittletyper.com/#pie https://thelittletyper.com/#pie>