Skip to content

Commit 1948b34

Browse files
committed
fix(core): make sure NgtThreeElements contain correct types for non-mutable props
1 parent 9a0ee1d commit 1948b34

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

libs/core/src/lib/three-types.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {
1111
export type NgtNonFunctionKeys<T> = { [K in keyof T]-?: T[K] extends Function ? never : K }[keyof T];
1212
export type NgtOverwrite<T, O> = Omit<T, NgtNonFunctionKeys<O>> & O;
1313
export type NgtProperties<T> = Pick<T, NgtNonFunctionKeys<T>>;
14-
export type NgtMutable<P> = { [K in keyof P]: P[K] | Readonly<P[K]> };
14+
export type NgtMutable<P> = { [K in keyof P]: P[K] extends Array<any> ? P[K] : P[K] | Readonly<P[K]> };
1515

1616
export interface NgtMathRepresentation {
1717
set(...args: number[]): any;
@@ -33,6 +33,15 @@ export type NgtMathProperties<P> = {
3333
[K in keyof P as P[K] extends NgtMathTypes ? K : never]: P[K] extends NgtMathTypes ? NgtMathType<P[K]> : never;
3434
};
3535

36+
export type NgtIsProperties<P> = {
37+
[K in keyof P as P[K] extends true ? K : never]: true;
38+
};
39+
40+
export type NgtNonMutableProperties = 'id' | 'uuid' | 'name' | 'type' | 'parent' | 'children';
41+
export type NgtNonPartialProperties<P> = {
42+
[K in keyof P as K extends NgtNonMutableProperties ? K : never]: P[K];
43+
};
44+
3645
export type NgtNullableRaycast<P> = {
3746
[K in keyof P as K extends 'raycast' ? K : never]: K extends 'raycast' ? P[K] | null : never;
3847
};
@@ -109,6 +118,8 @@ export type NgtElementProperties<
109118
TConstructor extends NgtConstructorRepresentation,
110119
TInstance = InstanceType<TConstructor>,
111120
> = Partial<NgtOverwrite<TInstance, NgtMathProperties<TInstance> & NgtNullableRaycast<TInstance>>> &
121+
NgtIsProperties<TInstance> &
122+
NgtNonPartialProperties<TInstance> &
112123
NgtNodeElement<TConstructor, TInstance>;
113124

114125
export type NgtThreeElement<TConstructor extends NgtConstructorRepresentation> = NgtMutable<

0 commit comments

Comments
 (0)