mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-08-07 07:59:26 +02:00
Maybe fixed typecheck error 0.5
This commit is contained in:
parent
349c1d052f
commit
2b72077af4
@ -25,19 +25,15 @@ export function loadPositionalTag<T extends PositionalTagType>({
|
|||||||
* This function does not perform any checking if the added tag is valid.
|
* This function does not perform any checking if the added tag is valid.
|
||||||
*/
|
*/
|
||||||
export function loadPositionalTag(tag: SerializedPositionalTag): PositionalTag;
|
export function loadPositionalTag(tag: SerializedPositionalTag): PositionalTag;
|
||||||
export function loadPositionalTag<T extends PositionalTagType>(tag: serializedPosTagMap[T]): posTagInstanceMap[T] {
|
export function loadPositionalTag(tag: SerializedPositionalTag): PositionalTag {
|
||||||
// Update the global arena flyout
|
// Update the global arena flyout
|
||||||
|
|
||||||
globalScene.arena.eventTarget.dispatchEvent(new PositionalTagAddedEvent(tag));
|
globalScene.arena.eventTarget.dispatchEvent(new PositionalTagAddedEvent(tag));
|
||||||
|
|
||||||
|
// Create the new tag
|
||||||
|
// TODO: review how many type assertions we need here
|
||||||
const { tagType, ...rest } = tag;
|
const { tagType, ...rest } = tag;
|
||||||
// Note: We need 2 type assertions here:
|
const tagClass = posTagConstructorMap[tagType];
|
||||||
// 1 because TS doesn't narrow the type of TagClass correctly based on `T`.
|
return new tagClass(rest);
|
||||||
// It converts it into `new (DelayedAttackTag | WishTag) => DelayedAttackTag & WishTag`
|
|
||||||
const tagClass = posTagConstructorMap[tagType] as new (args: posTagParamMap[T]) => posTagInstanceMap[T];
|
|
||||||
// 2 because TS doesn't narrow the type of `rest` correctly
|
|
||||||
// (from `Omit<serializedPosTagParamMap[T], "tagType"> into `posTagParamMap[T]`)
|
|
||||||
return new tagClass(rest as unknown as posTagParamMap[T]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Const object mapping tag types to their constructors. */
|
/** Const object mapping tag types to their constructors. */
|
||||||
|
Loading…
Reference in New Issue
Block a user