Closed UserC2 closed 3 weeks ago
The level of a player (and a member) cannot be set through the constructor, because the constructor only accepts undefined as an argument for level.
level
undefined
The level parameter has a type of undefined | Level (which is fine):
undefined | Level
level?: Level
However, the constructor looks like this:
// 'level' parameter has type 'undefined' constructor(name, level = undefined, is_guest = true, avatar_url = "") { this.name = name; this.avatarURL = avatar_url; this.isGuest = is_guest; this.level = level; // assigning 'undefined' to the level member (type 'undefined | Level') is allowed }
level has a default value of undefined, and no other type notation, so a type of undefined is inferred. This means a Level cannot be passed to it.
Level
Note that level: Level doesn't work because it won't have a default value anymore.
level: Level
Replace level = undefined with level?: Level (meaning level is undefined by default but can be assigned a Level).
level = undefined
Issue:
The
level
of a player (and a member) cannot be set through the constructor, because the constructor only acceptsundefined
as an argument forlevel
.Explanation:
The
level
parameter has a type ofundefined | Level
(which is fine):However, the constructor looks like this:
level
has a default value ofundefined
, and no other type notation, so a type ofundefined
is inferred. This means aLevel
cannot be passed to it.Note that
level: Level
doesn't work because it won't have a default value anymore.Fix:
Replace
level = undefined
withlevel?: Level
(meaninglevel
isundefined
by default but can be assigned aLevel
).