TS2749

error TS2749: ‘paramNames‘ refers to a value, but is being used as a type here. Did you mean ‘typeof paramNames‘?

Broken Code ❌

1
2
3
4
5
6
7
8
const paramNames = ['age', 'name'];

const person: {
[param in paramNames]: string
} = {
age: '34',
name: 'Benny'
};

Fixed Code ✔️

1
2
3
4
5
6
7
8
type paramNames = 'age' | 'name';

const person: {
[param in paramNames]: string
} = {
age: '34',
name: 'Benny'
};