l2lam / CBC-Board-System

Sports (badminton) club session management system to faciliate efficient, fair play for all club members
Apache License 2.0
1 stars 1 forks source link

The Player model doesn't allow 'level' to be set #52

Closed UserC2 closed 3 weeks ago

UserC2 commented 3 weeks ago

Issue:

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.

Explanation:

The level parameter has a type of undefined | Level (which is fine):

  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.

Note that level: Level doesn't work because it won't have a default value anymore.

Fix:

Replace level = undefined with level?: Level (meaning level is undefined by default but can be assigned a Level).