Skip to content

Commit

Permalink
fix(types): r153 colors overload fix
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyJasonBennett committed Jul 12, 2023
1 parent 0e45425 commit 1af68c1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion packages/fiber/src/core/reconciler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ export interface Catalogue {
[name: string]: ConstructorRepresentation
}

export type Args<T> = T extends ConstructorRepresentation ? ConstructorParameters<T> : any[]
// TODO: handle constructor overloads
// https://github.com/pmndrs/react-three-fiber/pull/2931
// https://github.com/microsoft/TypeScript/issues/37079
export type Args<T> = T extends ConstructorRepresentation
? T extends typeof THREE.Color
? [r: number, g: number, b: number] | [color: THREE.ColorRepresentation]
: ConstructorParameters<T>
: any[]

export interface InstanceProps<T = any, P = any> {
args?: Args<P>
Expand Down
4 changes: 2 additions & 2 deletions packages/fiber/src/three-types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type * as THREE from 'three'
import type { EventHandlers, InstanceProps, ConstructorRepresentation } from './core'
import type { Args, EventHandlers, InstanceProps, ConstructorRepresentation } from './core'
import type { Mutable, Overwrite } from './core/utils'

export { Overwrite }
Expand All @@ -12,7 +12,7 @@ interface VectorRepresentation extends MathRepresentation {
}

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

0 comments on commit 1af68c1

Please sign in to comment.