'Type annotation of a class inside its own class
I'm learning TypeScript and I'm adding type annotations to a JS file I had, and I'm wondering if doing something like this is right or not. And if not, what's the right way of doing it? As you can see below I added the Bomb type to the static method (p: Bomb)
TS in the VSC is not showing any errors.
class Bomb {
type: string;
color: string | null;
image: object;
x: number;
y: number;
isActive: boolean;
usingColumns: number[];
usingRows: number[];
constructor() {
this.type = "bomb"
this.color = null,
this.image = bombImage,
this.x = 120,
this.y = 0,
this.isActive = true,
this.usingColumns = [3],
this.usingRows = [0]
}
static explode(p: Bomb) { // <---- Can I do this?
// Some code to destroy surrounding pieces
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
