AG_1380
AG_1380

Reputation: 614

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

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?

Upvotes: 1

Views: 7014

Answers (1)

Matthieu Riegler
Matthieu Riegler

Reputation: 55554

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;

Upvotes: 2

Related Questions