This feels like a really dumb error, but I have a typescript class:
export class Stat{
abbr: StatType;
score: number;
mod: number;
get name(): string { return StatType[this.abbr]; }
}
The "name" property is read-only, right?
However, while dummying up some "stats", I get the error that I'm not defining "name".
const stats: Stat[] = [{
abbr: StatType.Str,
score: 15,
mod: 2
}]
Which produces the error: error TS2741: Property 'name' is missing in type '{ abbr: StatType.Str; score: number; mod: number; }' but required in type 'Stat'
But if the property "name" is read-only, why do I have to assign it a value?
And IF I assign a value, then that value is used, the get() property is ignored entirely.
Am I doing something wrong? How do I convince TS that I don't need to provide a name
property?
The enum is defined thusly:
export enum StatType{
Str,
Dex,
Con,
Int,
Wis,
Cha
}
Thanks!