-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Conflict with @types/react svg types in JSX.IntrinsicElements #172
Comments
unfortunately this is a TS bug, there are issues on their GH already, but microsoft keeps sticking dom types into the generic jsx definitions. i believe they think jsx is for the dom only. main issue: DefinitelyTyped/DefinitelyTyped#24433 at work we have resorted to a really ugly workaround, we use import * as THREE from 'three'
import { ReactThreeFiber } from 'react-three-fiber'
declare global {
// tslint:disable-next-line: no-namespace
namespace JSX {
// tslint:disable-next-line: interface-name
interface IntrinsicElements {
line_: ReactThreeFiber.Object3DNode<THREE.Line, typeof THREE.Line>
}
}
} and then import * as THREE from 'three'
import { Canvas, extend } from 'react-three-fiber'
extend({ Line_: THREE.Line })
...
<Canvas>
<line_ geometry={...} />
</Canvas> |
Got some valuable input on Twitter https://twitter.com/0xca0a/status/1163035106472341505?s=19 |
Thanks @drcmda! This is way better than my workaround :) const t = {
line: ('line' as any) as ((
_: ReactThreeFiber.Object3DNode<THREE.Line, typeof THREE.Line>
) => JSX.Element),
};
function Thing({ vertices }) {
return (
<t.line
onPointerDown={e => console.log(e)}
onUpdate={line => console.log(line)}
>
<geometry
attach="geometry"
vertices={vertices.map(v => new THREE.Vector3(...v))}
onUpdate={self => (self.verticesNeedUpdate = true)}
/>
<lineBasicMaterial attach="material" color="black" />
</t.line>
);
} Well, JSXAttributes isn't the best thing about TypeScript TBH. |
Okay, so according to what Sebastian Markbåge said about what React Native is doing, lying about the type is a recommended solution. With dynamic runtime eval (/ generated wrappers) the types would probably go somewhere in this direction 🙈 type ThreeFiberJsx = {
[P in keyof typeof THREE]: (typeof THREE)[P] extends (new () => Object3D)
? React.FC<
ReactThreeFiber.Object3DNode<
InstanceType<(typeof THREE)[P]>,
(typeof THREE)[P]
>
>
: never // GeometryNodes etc
}; |
I feel we can close this issue -- it overlaps with #11 . |
i reopened b/c that would be a feasible thing we could do. maybe a 3.x milestone? im still on vacation, but let's just keep this around, it could solve all our troubles. :-) |
we can continue here: #189 |
@drcmda Can you help me understand this proposed workaround? Is this meant to overwrite the typings that live in
|
this is what i saw in our project at work, but i don't know ts deep enough to know how it works. they seem to override these type. the extend function is clear but not the rest. i think better ask on spectrum, someone probably knows it. |
@codynova To get rid of errros you need to remove conflicting types from three-types.d.ts (audio and line) and patch package this file.
Sorry for answering here, but I couldn't find @codynova's question on Spectrum 😅. |
we didnt use patch-package though, we have a file called three-fiber.ts with the following contents: import * as THREE from 'three'
import { ReactThreeFiber } from 'react-three-fiber'
declare global {
// tslint:disable-next-line: no-namespace
namespace JSX {
// tslint:disable-next-line: interface-name
interface IntrinsicElements {
line_: ReactThreeFiber.Object3DNode<THREE.Line, typeof THREE.Line>
// ...
}
}
} we import it in the index.js, i guess after three-fiber makes its own declarations, and that overrides it just fine. |
@drcmda Do you have I've updated my repro repo to new packages version and I'm still getting the error.
|
this is our config, i didn't make it so im just posting it here: {
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"lib": ["es5", "es2015.promise", "es2016", "dom"],
"outDir": "build/",
"baseUrl": "./",
"strict": true,
"allowJs": false,
"declaration": true,
"preserveConstEnums": true,
"sourceMap": true,
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"noImplicitAny": true,
"strictFunctionTypes": true,
"noImplicitThis": true,
"alwaysStrict": true,
"jsx": "react"
},
"include": ["./src/**/*"]
} |
@hasparus That must be it. If |
Notice that we only add |
@hasparus Right, I think we are maybe saying the same thing. But, is there any reason not to just use |
@codynova Yeah and after you do this you'd have to add I'll try to do a PR with React Native inspired (#172 (comment)) fix for this issue. EDIT: Actually if I'm right about how react-three-fiber dynamic runtime eval works, instead of using |
@hasparus If you make that PR, I will post a boilerplate react-three-fiber, TypeScript, SCSS modules, hot module reloading repo this weekend with leading-edge versions of all dependencies. |
@codynova I'm afraid you'd have to wait to next weekend for my PR. |
No rush. I'm using patch-package for now. Just @ me whenever |
I used to import |
Hi! I've encountered a little problem while using react-three-fiber in TypeScript.
@types/react
conflicts withthree-types.d.ts
on global JSX.IntrinsicElements.Is there a workaround to avoid it?
Repro: https://codesandbox.io/s/react-three-fiber-types-conflict-repro-ydr2t
(CodeSandbox seems to be few TS versions behind so there's another problem there -- Omit type is not defined, and because of it Object3DNode is any. The conflict I mentioned still occurs regardless of it.)
The text was updated successfully, but these errors were encountered: