Skip to content

Commit cca8a12

Browse files
committed
fix(soba): adjust injectAnimations to be more relaxed with animation clip typing
1 parent ceb8375 commit cca8a12

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

libs/soba/misc/src/lib/animations.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,29 @@ import { injectBeforeRender, resolveRef } from 'angular-three';
33
import { assertInjector } from 'ngxtension/assert-injector';
44
import { AnimationAction, AnimationClip, AnimationMixer, Object3D } from 'three';
55

6-
type NgtsAnimationApi<T extends AnimationClip> = {
7-
clips: AnimationClip[];
6+
/**
7+
* name: any to allow consumers to pass in type-safe animation clips
8+
*/
9+
type NgtsAnimationClipWithoutName = Omit<AnimationClip, 'name'> & { name: any };
10+
type NgtsAnimationClip = Omit<NgtsAnimationClipWithoutName, 'clone'> & { clone: () => NgtsAnimationClip };
11+
type NgtsAnimationClips<TAnimationNames extends string> = {
12+
[Name in TAnimationNames]: Omit<NgtsAnimationClip, 'name'> & { name: Name };
13+
}[TAnimationNames];
14+
type NgtsAnimationApi<T extends NgtsAnimationClip> = {
15+
clips: T[];
816
mixer: AnimationMixer;
917
names: T['name'][];
1018
actions: { [key in T['name']]: AnimationAction | null };
1119
};
1220

13-
export type NgtsAnimation<TAnimation extends AnimationClip = AnimationClip> =
21+
export type NgtsAnimation<TAnimation extends NgtsAnimationClip = NgtsAnimationClip> =
1422
| TAnimation[]
1523
| { animations: TAnimation[] };
1624

1725
/**
1826
* Use afterNextRender
1927
*/
20-
export function injectAnimations<TAnimation extends AnimationClip>(
28+
export function injectAnimations<TAnimation extends NgtsAnimationClip>(
2129
animations: () => NgtsAnimation<TAnimation> | undefined | null,
2230
object: ElementRef<Object3D> | Object3D | (() => ElementRef<Object3D> | Object3D | undefined | null),
2331
{ injector }: { injector?: Injector } = {},

0 commit comments

Comments
 (0)