Skip to content

Commit

Permalink
fix: harden vector type
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyJasonBennett committed May 27, 2024
1 parent a5a9553 commit 10c2746
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
9 changes: 4 additions & 5 deletions packages/fiber/src/three-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,21 @@ import type { Args, EventHandlers, InstanceProps, ConstructorRepresentation } fr
import type { Overwrite, Mutable } from './core/utils'

export interface MathRepresentation {
set(...args: any[]): any
set(...args: number[]): any
}
export interface VectorRepresentation extends MathRepresentation {
setScalar(value: number): any
}
export type MathTypes = MathRepresentation | THREE.Euler | THREE.Color

export type MathType<T extends MathRepresentation> = T extends THREE.Color
export type MathType<T extends MathTypes> = T extends THREE.Color
? Args<typeof THREE.Color> | THREE.ColorRepresentation
: T extends VectorRepresentation | THREE.Layers | THREE.Euler
? T | Parameters<T['set']> | number
: T | Parameters<T['set']>

export type MathProps<P> = {
[K in keyof P as P[K] extends MathRepresentation ? K : never]: P[K] extends MathRepresentation
? MathType<P[K]>
: never
[K in keyof P as P[K] extends MathTypes ? K : never]: P[K] extends MathTypes ? MathType<P[K]> : never
}

export type Vector2 = MathType<THREE.Vector2>
Expand Down
1 change: 1 addition & 0 deletions packages/fiber/tests/__snapshots__/index.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Array [
"MathProps",
"MathRepresentation",
"MathType",
"MathTypes",
"Matrix3",
"Matrix4",
"ObjectMap",
Expand Down

0 comments on commit 10c2746

Please sign in to comment.