on-internet
← Community

How to use branded string as an index to a Record type

Stack Overflow ·

My strings take a certain format so I often type them to be sure they are in a particular format. For example I check my strings are prefixed with foo. How can I use a branded string as an index to a record? type Foo = string & { _fooBrand: undefined } type T = Record<Foo, string> const f = (a: T, b: Foo) => { const c = a[b] // Type 'Foo' cannot be used as an index type. }

Comments

Sign in or sign up to comment and upvote.

No comments yet.