Home > other >  refers to a value, but is being used as a type here. Did you mean 'typeof ' ? ts(2749)
refers to a value, but is being used as a type here. Did you mean 'typeof ' ? ts(2749)

Time:10-05

I was developing a minesweeper game in typescript. But while defining a type named Cell, I encountered an error.

Code:

Not Working

const bomb = "💣";
const flag = "🚩";

export type Cell = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | bomb | flag;

export type Board = Array<Array<Cell>>;

While defining type Cell the error raises:

'bomb' refers to a value, but is being used as a type here. Did you mean 'typeof bomb'?ts(2749)

while doing it in another way without any variable or constant works:

Fine

export type Cell = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | "&#128163;" | "&#128681;";

What am I doing wrong? What is the reason?

CodePudding user response:

bomb and flag and not types.

The typeof operator will give you access to the type of a value.

const bomb = "&#128163;";
const flag = "&#128681;";

export type Cell = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | typeof bomb | typeof flag;
  • Related