Skip to content

Commit

Permalink
feat: typed get (#379)
Browse files Browse the repository at this point in the history
  • Loading branch information
lajbel committed Sep 1, 2024
1 parent 7766f64 commit f69edcb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<BodyComp>("player");
```

## Deprecations

> All changes applies for both v3001 and v4000
Expand Down
2 changes: 1 addition & 1 deletion src/game/make.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ export function make<T>(comps: CompList<T> = []): GameObj<MakeType<T>> {
},

// TODO: Separate
get(t: Tag | Tag[], opts: GetOpt = {}): GameObj[] {
get<T = any>(t: Tag | Tag[], opts: GetOpt = {}): GameObj<T>[] {
let list: GameObj[] = opts.recursive
? this.children.flatMap(
function recurse(child: GameObj): GameObj[] {
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export interface KAPLAYCtx<
*
* @group Game Obj
*/
get<T>(tag: Tag | Tag[], opts?: GetOpt): GameObj<T>[];
get<T = any>(tag: Tag | Tag[], opts?: GetOpt): GameObj<T>[];
/**
* Get a list of game objects in an advanced way.
*
Expand Down Expand Up @@ -3997,7 +3997,7 @@ export interface GameObjRaw {
*
* @since v3000.0
*/
get(tag: Tag | Tag[], opts?: GetOpt): GameObj[];
get<T = any>(tag: Tag | Tag[], opts?: GetOpt): GameObj<T>[];
/**
* Get a list of all game objs with certain properties.
*
Expand Down

0 comments on commit f69edcb

Please sign in to comment.