/
spell.ts
27 lines (25 loc) · 1015 Bytes
/
spell.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { Constructor, Executable } from './executable';
/**
* An interface containing method type signatures for any `.ddragon` Action containing a `.spell()` method.
*/
export interface SpellChainable {
spell?: <K extends SpellChainable & Executable>(this: K, spell: string) => Omit<K, 'spell'>;
}
/**
* A mixin for the `.spell()` method.
* @template TBase The type of the object inside. Inferred from the `Base` parameter.
* @param Base The target class.
*/
export function TakesSpell<TBase extends Constructor>(Base: TBase) {
return class extends Base implements SpellChainable {
/**
* Modifies the **spell** associated with the Action object it is called from.
* @param spell The spell name to update the calling Action object with.
*/
public spell<K extends SpellChainable & Executable>(this: K, spell: string): Omit<K, 'spell'> {
this.payload.spell = spell;
this.spell = undefined;
return this;
}
};
}