Skip to content

Commit

Permalink
Remove Properties utility type and use Pick directly instead, because…
Browse files Browse the repository at this point in the history
… Properties includes a class's methods, not just its properties, which is not desired, but cannot be worked around at this time, because TypeScript currently offers no way to form a union type of only those instance properties of a type which equal undefined on its prototype, presumably because a prototype is a value, not a type, and only types can be queried at compile time because that's the simple and straightforward way for it to work, in spite of the fact that the initial state of a class's prototype object at runtime *could* be statically calculated at compile time by analyzing the class's structure, if they *wanted* to, harumpf harumpf.
  • Loading branch information
blujai831 committed Oct 11, 2024
1 parent db594fc commit e414404
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
11 changes: 9 additions & 2 deletions src/GameUpgrade.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {IGameState} from "./IGameState.ts";
import {IGameUpgrade} from "./IGameUpgrade.ts";
import {Properties} from "./util.ts";

/**
* See IGameUpgrade.
Expand Down Expand Up @@ -93,7 +92,15 @@ export class GameUpgrade implements IGameUpgrade {
* the instance's properties, mimicking C/++'s designated initializers.
* @param properties Keyword arguments / property donor object.
*/
public constructor(properties: Properties<GameUpgrade>) {
public constructor(properties: Pick<GameUpgrade,
'effectOrder' |
'speedFormulaEffect' |
'purchaseCondition' |
'purchaseAckMessage' |
'purchaseNakMessage' |
'postPurchaseEffect' |
'tickEffect'
>) {
Object.assign(this, properties);
}
}
6 changes: 0 additions & 6 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
/**
* Gets the type of a plain object that has the same properties
* as an instance of the given class.
*/
export type Properties<Klass> = Pick<Klass, keyof Klass>;

/**
* Applies an appropriate ordinal suffix to the given number
* (i.e. "-st", "-nd", "-rd", or "-th").
Expand Down

0 comments on commit e414404

Please sign in to comment.