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

chore(types): suppress errors with @ts-expect-error directive instead of @ts-ignore #3259

Merged
merged 7 commits into from
May 8, 2024
4 changes: 2 additions & 2 deletions example/src/demos/Lines.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function useDrag(onDrag: any, onEnd: any) {
setActive(true)
toggle(false)
event.stopPropagation()
// @ts-ignore
// @ts-expect-error
event.target.setPointerCapture(event.pointerId)
}

Expand All @@ -41,7 +41,7 @@ function useDrag(onDrag: any, onEnd: any) {
setActive(false)
toggle(true)
event.stopPropagation()
// @ts-ignore
// @ts-expect-error
event.target.releasePointerCapture(event.pointerId)
if (onEnd) onEnd()
}
Expand Down
4 changes: 2 additions & 2 deletions packages/fiber/src/core/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function createRenderer<TCanvas>(_roots: Map<TCanvas, Root>, _getEventPriority?:
detach(parentInstance, child, child.__r3f.attach)
} else if (child.isObject3D && parentInstance.isObject3D) {
parentInstance.remove(child)
// @ts-ignore
// @ts-expect-error
// Remove interactivity on the initial root
if (child.__r3f?.root) {
removeInteractivity(findInitialRoot(child), child as unknown as THREE.Object3D)
Expand Down Expand Up @@ -426,7 +426,7 @@ function createRenderer<TCanvas>(_roots: Map<TCanvas, Root>, _getEventPriority?:
hideTextInstance: handleTextInstance,
unhideTextInstance: handleTextInstance,
// https://github.com/pmndrs/react-three-fiber/pull/2360#discussion_r916356874
// @ts-ignore
// @ts-expect-error
getCurrentEventPriority: () => (_getEventPriority ? _getEventPriority() : DefaultEventPriority),
beforeActiveInstanceBlur: () => {},
afterActiveInstanceBlur: () => {},
Expand Down
4 changes: 1 addition & 3 deletions packages/fiber/src/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import { AttachType, catalogue, Instance, InstanceProps, LocalState } from './re
import { Dpr, Renderer, RootState, Size } from './store'

// < r141 shipped vendored types https://github.com/pmndrs/react-three-fiber/issues/2501
/** @ts-ignore */
Copy link
Member

@CodyJasonBennett CodyJasonBennett May 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that any /** @ts-ignore */ is intended to be kept and are user-facing at build-time #3062. This won't be an issue in v9.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CodyJasonBennett But why? The build doesn't seem to fail because there's no error for them. Am I missing something?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these types are removed in future three types, but we need to keep them here so they are dynamically used if available.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, got it, I'll get them back then.
Great thing tho that v9 will have those being fully dynamic: #3038 (comment) 💎

type _DeprecatedXRFrame = THREE.XRFrame
/** @ts-ignore */
export type _XRFrame = THREE.WebGLRenderTargetOptions extends { samples?: number } ? XRFrame : _DeprecatedXRFrame

/**
Expand Down Expand Up @@ -352,7 +350,7 @@ export function applyProps(instance: Instance, data: InstanceProps | DiffSet) {
// create a blank slate of the instance and copy the particular parameter.
let ctor = DEFAULTS.get(currentInstance.constructor)
if (!ctor) {
// @ts-ignore
// @ts-expect-error
ctor = new currentInstance.constructor()
DEFAULTS.set(currentInstance.constructor, ctor)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/fiber/src/native/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export function polyfills() {
texture.needsUpdate = true

// Force non-DOM upload for EXGL texImage2D
// @ts-ignore
// @ts-expect-error
texture.isDataTexture = true

onLoad?.(texture)
Expand Down
32 changes: 0 additions & 32 deletions packages/fiber/src/three-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,81 +98,53 @@ export type InstancedBufferGeometryProps = BufferGeometryNode<
typeof THREE.InstancedBufferGeometry
>
export type BufferGeometryProps = BufferGeometryNode<THREE.BufferGeometry, typeof THREE.BufferGeometry>
/** @ts-ignore */
export type BoxBufferGeometryProps = BufferGeometryNode<THREE.BoxBufferGeometry, typeof THREE.BoxBufferGeometry>
export type CircleBufferGeometryProps = BufferGeometryNode<
/** @ts-ignore */
THREE.CircleBufferGeometry,
/** @ts-ignore */
typeof THREE.CircleBufferGeometry
>
/** @ts-ignore */
export type ConeBufferGeometryProps = BufferGeometryNode<THREE.ConeBufferGeometry, typeof THREE.ConeBufferGeometry>
export type CylinderBufferGeometryProps = BufferGeometryNode<
/** @ts-ignore */
THREE.CylinderBufferGeometry,
/** @ts-ignore */
typeof THREE.CylinderBufferGeometry
>
export type DodecahedronBufferGeometryProps = BufferGeometryNode<
/** @ts-ignore */
THREE.DodecahedronBufferGeometry,
/** @ts-ignore */
typeof THREE.DodecahedronBufferGeometry
>
export type ExtrudeBufferGeometryProps = BufferGeometryNode<
/** @ts-ignore */
THREE.ExtrudeBufferGeometry,
/** @ts-ignore */
typeof THREE.ExtrudeBufferGeometry
>
export type IcosahedronBufferGeometryProps = BufferGeometryNode<
/** @ts-ignore */
THREE.IcosahedronBufferGeometry,
/** @ts-ignore */
typeof THREE.IcosahedronBufferGeometry
>
/** @ts-ignore */
export type LatheBufferGeometryProps = BufferGeometryNode<THREE.LatheBufferGeometry, typeof THREE.LatheBufferGeometry>
export type OctahedronBufferGeometryProps = BufferGeometryNode<
/** @ts-ignore */
THREE.OctahedronBufferGeometry,
/** @ts-ignore */
typeof THREE.OctahedronBufferGeometry
>
/** @ts-ignore */
export type PlaneBufferGeometryProps = BufferGeometryNode<THREE.PlaneBufferGeometry, typeof THREE.PlaneBufferGeometry>
export type PolyhedronBufferGeometryProps = BufferGeometryNode<
/** @ts-ignore */
THREE.PolyhedronBufferGeometry,
/** @ts-ignore */
typeof THREE.PolyhedronBufferGeometry
>
/** @ts-ignore */
export type RingBufferGeometryProps = BufferGeometryNode<THREE.RingBufferGeometry, typeof THREE.RingBufferGeometry>
/** @ts-ignore */
export type ShapeBufferGeometryProps = BufferGeometryNode<THREE.ShapeBufferGeometry, typeof THREE.ShapeBufferGeometry>
export type SphereBufferGeometryProps = BufferGeometryNode<
/** @ts-ignore */
THREE.SphereBufferGeometry,
/** @ts-ignore */
typeof THREE.SphereBufferGeometry
>
export type TetrahedronBufferGeometryProps = BufferGeometryNode<
/** @ts-ignore */
THREE.TetrahedronBufferGeometry,
/** @ts-ignore */
typeof THREE.TetrahedronBufferGeometry
>
/** @ts-ignore */
export type TorusBufferGeometryProps = BufferGeometryNode<THREE.TorusBufferGeometry, typeof THREE.TorusBufferGeometry>
export type TorusKnotBufferGeometryProps = BufferGeometryNode<
/** @ts-ignore */
THREE.TorusKnotBufferGeometry,
/** @ts-ignore */
typeof THREE.TorusKnotBufferGeometry
>
/** @ts-ignore */
export type TubeBufferGeometryProps = BufferGeometryNode<THREE.TubeBufferGeometry, typeof THREE.TubeBufferGeometry>
export type WireframeGeometryProps = BufferGeometryNode<THREE.WireframeGeometry, typeof THREE.WireframeGeometry>
export type TetrahedronGeometryProps = BufferGeometryNode<THREE.TetrahedronGeometry, typeof THREE.TetrahedronGeometry>
Expand Down Expand Up @@ -230,9 +202,7 @@ export type DirectionalLightShadowProps = Node<THREE.DirectionalLightShadow, typ
export type DirectionalLightProps = LightNode<THREE.DirectionalLight, typeof THREE.DirectionalLight>
export type AmbientLightProps = LightNode<THREE.AmbientLight, typeof THREE.AmbientLight>
export type LightShadowProps = Node<THREE.LightShadow, typeof THREE.LightShadow>
/** @ts-ignore */
export type AmbientLightProbeProps = LightNode<THREE.AmbientLightProbe, typeof THREE.AmbientLightProbe>
/** @ts-ignore */
export type HemisphereLightProbeProps = LightNode<THREE.HemisphereLightProbe, typeof THREE.HemisphereLightProbe>
export type LightProbeProps = LightNode<THREE.LightProbe, typeof THREE.LightProbe>

Expand All @@ -256,7 +226,6 @@ export type AxesHelperProps = Object3DNode<THREE.AxesHelper, typeof THREE.AxesHe
export type TextureProps = Node<THREE.Texture, typeof THREE.Texture>
export type VideoTextureProps = Node<THREE.VideoTexture, typeof THREE.VideoTexture>
export type DataTextureProps = Node<THREE.DataTexture, typeof THREE.DataTexture>
/** @ts-ignore */
export type DataTexture3DProps = Node<THREE.DataTexture3D, typeof THREE.DataTexture3D>
export type CompressedTextureProps = Node<THREE.CompressedTexture, typeof THREE.CompressedTexture>
export type CubeTextureProps = Node<THREE.CubeTexture, typeof THREE.CubeTexture>
Expand All @@ -274,7 +243,6 @@ export type QuaternionProps = Node<THREE.Quaternion, typeof THREE.Quaternion>
export type BufferAttributeProps = Node<THREE.BufferAttribute, typeof THREE.BufferAttribute>
export type Float16BufferAttributeProps = Node<THREE.Float16BufferAttribute, typeof THREE.Float16BufferAttribute>
export type Float32BufferAttributeProps = Node<THREE.Float32BufferAttribute, typeof THREE.Float32BufferAttribute>
/** @ts-ignore */
export type Float64BufferAttributeProps = Node<THREE.Float64BufferAttribute, typeof THREE.Float64BufferAttribute>
export type Int8BufferAttributeProps = Node<THREE.Int8BufferAttribute, typeof THREE.Int8BufferAttribute>
export type Int16BufferAttributeProps = Node<THREE.Int16BufferAttribute, typeof THREE.Int16BufferAttribute>
Expand Down
8 changes: 4 additions & 4 deletions packages/fiber/tests/core/renderer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -746,9 +746,9 @@ describe('renderer', () => {
expect(gl.toneMapping).toBe(THREE.ACESFilmicToneMapping)
expect(texture.encoding).toBe(sRGBEncoding)

// @ts-ignore
// @ts-expect-error
THREE.WebGLRenderer.prototype.outputColorSpace ??= ''
// @ts-ignore
// @ts-expect-error
THREE.Texture.prototype.colorSpace ??= ''

await act(async () =>
Expand Down Expand Up @@ -780,9 +780,9 @@ describe('renderer', () => {
expect(gl.outputColorSpace).toBe(SRGBColorSpace)
expect(texture.colorSpace).toBe(SRGBColorSpace)

// @ts-ignore
// @ts-expect-error
delete THREE.WebGLRenderer.prototype.outputColorSpace
// @ts-ignore
// @ts-expect-error
delete THREE.Texture.prototype.colorSpace
})

Expand Down
4 changes: 2 additions & 2 deletions packages/test-renderer/src/createTestCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export const createCanvas = ({ beforeReturn, width = 1280, height = 800 }: Creat
beforeReturn?.(canvas)

class WebGLRenderingContext extends WebGL2RenderingContext {}
// @ts-ignore
// @ts-expect-error
globalThis.WebGLRenderingContext ??= WebGLRenderingContext
// @ts-ignore
// @ts-expect-error
globalThis.WebGL2RenderingContext ??= WebGL2RenderingContext

return canvas
Expand Down