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

XRFrame type resolving incorrectly #3190

Closed
Methuselah96 opened this issue Mar 2, 2024 · 2 comments · Fixed by #3196
Closed

XRFrame type resolving incorrectly #3190

Methuselah96 opened this issue Mar 2, 2024 · 2 comments · Fixed by #3196
Labels
bug Something isn't working Typescript issues to do with TS

Comments

@Methuselah96
Copy link
Contributor

Methuselah96 commented Mar 2, 2024

This is a follow-up to #2501 and #3110. I do not believe the XRFrame workaround introduced in #3052 is working as intended.

It seems that TypeScript is evaluating the _XRFrame conditional type at declaration emit time, which results in emitting THREE.XRFrame in the declaration files instead of emitting _XRFrame. This causes errors for users with a @types/three version that does not contain THREE.XRFrame.

Here are the errors I get when type-checking:

./node_modules/@react-three/fiber/dist/declarations/src/core/index.d.ts:14:187 - error TS2694: Namespace '"./node_modules/@types/three/build/three.module"' has no exported member 'XRFrame'.

14 declare const invalidate: (state?: RootState | undefined, frames?: number) => void, advance: (timestamp: number, runGlobalEffects?: boolean, state?: RootState | undefined, frame?: THREE.XRFrame | undefined) => void;
                                                                                                                                                                                             ~~~~~~~

./node_modules/@react-three/fiber/dist/declarations/src/core/loop.d.ts:32:117 - error TS2694: Namespace '"./node_modules/@types/three/build/three.module"' has no exported member 'XRFrame'.

32     advance: (timestamp: number, runGlobalEffects?: boolean, state?: RootState | undefined, frame?: import("three").XRFrame | undefined) => void;
                                                                                                                       ~~~~~~~

./node_modules/@react-three/fiber/dist/declarations/src/core/store.d.ts:136:225 - error TS2694: Namespace '"./node_modules/@types/three/build/three.module"' has no exported member 'XRFrame'.

136 declare const createStore: (invalidate: (state?: RootState | undefined, frames?: number | undefined) => void, advance: (timestamp: number, runGlobalEffects?: boolean | undefined, state?: RootState | undefined, frame?: THREE.XRFrame | undefined) => void) => UseBoundStore<RootState>;
                                                                                                                                                                                                                                    ~~~~~~~


Found 3 errors in 3 files.
@Methuselah96 Methuselah96 changed the title XRFrame types resolving incorrectly XRFrame type resolving incorrectly Mar 2, 2024
@CodyJasonBennett CodyJasonBennett added bug Something isn't working Typescript issues to do with TS labels Mar 3, 2024
@CodyJasonBennett
Copy link
Member

CodyJasonBennett commented Mar 3, 2024

Is there a way we can prevent TS from evaluating and unfolding the type? I believe we still use older three types for testing. Noticed the same issues when using an updated version and/or testing ConstructorParameters<typeof THREE.WebGLRenderTarget>[2] for feature detection.

@Methuselah96
Copy link
Contributor Author

Methuselah96 commented Mar 3, 2024

It seems like this is happening when an exported value is not explicitly annotated with a type declaration. Making sure that exported values that reference _XRFrame are explicitly annotated as they will appear in the emitted declaration file seems to fix it. #3196 applies those changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Typescript issues to do with TS
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants