Midhun Raj
Midhun Raj

Reputation: 987

What does [propName: string]: any; mean in typescript

What does this piece of code mean [propName: string]: any; What concept is implemented here.I have heard one guy telling to me as this is indexers.Is it true.If so What is it.

interface SquareConfig {
  color?: string;
  width?: number;
  [propName: string]: any;
}

Whay does [propName: string]: any; Is it an array of string names that can be declared there

Upvotes: 0

Views: 1946

Answers (2)

Sri Kanth
Sri Kanth

Reputation: 151

If you declare like that for any of the component props interface then that component will accept anything as a prop i.e., you can pass any propName for that component.

Upvotes: 4

Jörg W Mittag
Jörg W Mittag

Reputation: 369488

It doesn't mean anything, it is not syntactically legal.:

'string' only refers to a type, but is being used as a value here.
'any' only refers to a type, but is being used as a value here.
',' expected.
';' expected.

Upvotes: -1

Related Questions