I am making a Black Jack app in pure TypeScript, but I get an error when creating the cards inside of a deck.
So far I have 2 classes and 2 enums to work with.
export enum Color {
Hearts = 0,
Spades,
Diamonds,
Clubs,
Count,
Hidden,
}
export enum Value {
Two = 0,
Three,
Four,
Five,
Six,
Seven,
Eight,
Nine,
Ten,
Knight,
Queen,
King,
Ace,
Count,
Hidden,
}
export class Card {
private color: Color;
private value: Value;
private isHidden: Boolean;
constructor(color: Color, value: Value) {
this.color = color;
this.value = value;
this.isHidden = true;
}
}
import { Card, Color, Value } from './Card';
export default class Deck {
private cards: Array<Card> = [];
public Deck = (): void => {
for (let colorIx = 0; colorIx < Color.Count; colorIx++) {
for (let valueIx = 0; valueIx < Value.Count; valueIx++) {
let c = new Card(Color[colorIx], Value[valueIx]);
this.AddCard(c);
}
}
};
public AddCard = (card: Card): void => {
this.cards.push(card);
};
}
This part here is where things go wrong.
let c = new Card(Color[colorIx], Value[valueIx]);
It, gives me an error saying:
Argument of type 'string' is not assignable to parameter of type 'Color'.
But the weird thing is that the Value enum does not give me an error at all, and as far as I can see they are pretty much the same in their construction.
Anyone knows what is going on?
Why is one enum accepted (Value) in the constructor while the other (Color) isnt?