Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v9] fix: r153 colors overload #2932

Merged
merged 1 commit into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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