What are "mapped types" in TypeScript?

1 month ago 37
ARTICLE AD BOX

An existing codebase has this interface declaration:

type TForValue = boolean | string; interface ISomeInterface { parameters: { [parameter: string]: TForValue }; foo: number; }

What is the type or meaning of parameters in this interface?

How would I create an object that satisfies this interface? What syntax would I use for that?

My initial thought was that parameters is simply a map from string to TForValue, but that idea appears to be completely misguided - I cannot assign a Map<string, TForValue> to parameters nor construct a Map<string, TForValue> object from parameters, so my thinking is that parameters cannot be a map.

I have read the docs on "mapped types" but it was not helpful to me.

I have entered this syntax in TypeScript Playground and in my IDE (PyCharm), but neither shows any helpful completion for members of the parameters field.

jonrsharpe's user avatar

jonrsharpe

124k31 gold badges279 silver badges489 bronze badges

oliver's user avatar

9

Read Entire Article