From f69edcb78541112e2d704245cf303a1f391653d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20B=C3=A1ez?= Date: Sun, 1 Sep 2024 10:58:49 -0300 Subject: [PATCH] feat: typed get (#379) --- CHANGELOG.md | 9 +++++++++ src/game/make.ts | 2 +- src/types.ts | 4 ++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7eeba9f..bb21e82e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -325,6 +325,15 @@ features of v4000, while v4000 will have the most features and breaking changes. - added evaluation of the first and second derivatives for all splines - added higher order easing functions linear, steps and cubic-bezier +## TypeScript + +- now you can type `get()` with a type parameter and passsing component types. + (**v4000**) + + ```ts + const player = get("player"); + ``` + ## Deprecations > All changes applies for both v3001 and v4000 diff --git a/src/game/make.ts b/src/game/make.ts index f370cf77..7cef1eb5 100644 --- a/src/game/make.ts +++ b/src/game/make.ts @@ -353,7 +353,7 @@ export function make(comps: CompList = []): GameObj> { }, // TODO: Separate - get(t: Tag | Tag[], opts: GetOpt = {}): GameObj[] { + get(t: Tag | Tag[], opts: GetOpt = {}): GameObj[] { let list: GameObj[] = opts.recursive ? this.children.flatMap( function recurse(child: GameObj): GameObj[] { diff --git a/src/types.ts b/src/types.ts index 0e227791..1b8dfcb4 100644 --- a/src/types.ts +++ b/src/types.ts @@ -282,7 +282,7 @@ export interface KAPLAYCtx< * * @group Game Obj */ - get(tag: Tag | Tag[], opts?: GetOpt): GameObj[]; + get(tag: Tag | Tag[], opts?: GetOpt): GameObj[]; /** * Get a list of game objects in an advanced way. * @@ -3997,7 +3997,7 @@ export interface GameObjRaw { * * @since v3000.0 */ - get(tag: Tag | Tag[], opts?: GetOpt): GameObj[]; + get(tag: Tag | Tag[], opts?: GetOpt): GameObj[]; /** * Get a list of all game objs with certain properties. *