Burak
Burak

Reputation: 710

Getting type of index signature

Is it possible to create a type that can get the type part of the index signature? Example:

type Foo = { [id: string]: Date }

type IndexSignatureType<T> = ???

const bar: IndexSignatureType<Foo>; // has type Date

Upvotes: 1

Views: 40

Answers (1)

Titian Cernicova-Dragomir
Titian Cernicova-Dragomir

Reputation: 249506

You can just use an index type query:

type Foo = { [id: string]: Date }    
const bar: Foo[string]; // is Date

Upvotes: 1

Related Questions