-
-
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
Fix type conflict with @types/react #233
Conversation
thanks for this! it's lots to take in, so, the change here is that there's an optional way to get components and it isn't that much weight? native elements are still working? i would also prefer react-three-fiber/components btw i think that would make imports cleaner |
That would also contribute to autoimport, so when I write the text editor can propose me to import Mesh from three or a Mesh from react-three-fiber/components.
Yup, I didn't touch the reconciler. I removed audio and line from types. I've noticed that the editor support I get on them prefers their declarations from @types/react. They still work at runtime though.
Ouch. It's good you've mentioned it. The I imported three (which is huge) and ran Object.entries on it to generate the I'm not sure if this is a problem, though. Doesn't react-three-fiber imports entire three already? Possible solutions:This is a long shot, because I'm not sure if it's a problem, but I'll run through possible solutions. I'll try to measure bundle size in a demo app to make sure.
|
if it's under /components i'm ok with it, it wouldn't matter if it pulls the entirety of three because it doesn't treeshake anyway. the only way i am aware of is using aliases, this is what i do to compress my projects and that would work with these wrapper components as well. the only sore spot is
that one is something i wanted to avoid. tying the lib to a particular three version, or being forced to track their release cycle is not ideal. one more question i have is about the extend function. how would that go? currently: import { extend } from 'react-three-fiber'
import { SpecialThing } from 'xyz'
extend({ SpecialThing })
<specialThing /> i know it would work like always, but wouldn't it then be confusing that you still have to rely on native elements? i've been thinking about another special object, like this: import { SpecialThing } from 'xyz'
<new object={SpecialThing} args={[...]} {...props} /> primitive = channels pre-existing objects into the graph |
Yeah, this is a big disadvantage. Especially because three is at version 0.x since forever and this page can be kinda scary when you have a large project.
I totally agree with it. This is a selling point of react-three-fiber. I think I can do something that enables named imports from
This could work too import { extend } from 'react-three-fiber'
import { SpecialThing } from 'xyz'
/* extend could return "specialThing" with a fake wrapper component type */
const { SpecialThing: Special } = extend({ SpecialThing })
<Special /> |
I think you can't get intrinsic elements to be generic, so this wouldn't autocomplete/typecheck. import { New } from 'react-three-fiber'
import { SpecialThing } from 'xyz'
<New object={SpecialThing} args={[...]} {...props} /> Using a component for that (regardless if the logic is actually inside of it or in the reconciler) would be easier IMHO. I've made a quick example in TypeScript playground https://links.typescript.social/5J6n |
I'm gonna try to get named imports from @codynova You might be interested in this PR. |
I can't use So if I'm not wrong, the only way to get named imports of object entries, would be to transform this object into a module at build time. I see two problems with it.
|
and proxies? i mean, this would basically be an add-on anyway so people know what they're getting into. this wouldn't tie it too close to the main lib and we're not dependent to a threejs version. not sure about types, but you're the pros, it can probably be done in some way or another. |
Well, since we can't export object as a module it makes no difference if it's computed at the startup of the app (like I do with Shipping without ES6 modules would be a regression and not worth the gain IMO.
By no means :D |
so, if we have an optional react-three-fiber/components esm export, not tied to the main export. and it's primed to three@latest and we find someone that likes to update it regularly or leave it to the community to update it via pr's, would it then be good to go? |
Yeah, I can add a script to package.json to dump what is right now components object into a components.tsx module so a PR to update it would be pretty easy to do. Classes exported by three don't change that often so a github action / a cron job would probably be a overkill. |
yes, please, no cron jobs :-D it could just use the threefiber main three devdependency to generate this file yarn build. |
I couldn't just print all I have also added |
what's your take on this? should we merge? is it safe? |
I've used it a little bit already, though I can't share the project. I'm gonna do the pool game tutorial using this and deploy the results this week. Maybe I'll find some problems along the way. This is technically a breaking change for people using |
seriously, who's using our types without @types/react 🙂but i would be ok with it. any other ideas that could go into a major? |
Well, I didn't finish my pool game, but I've fixed merge conflicts and adapted |
im gonna add a v4 branch today, is it possible to target this one in this pr instead of master? |
I've noticed you're publishing just `dist` right now. That's super nice. I'm changing types outdir, so `components.d.ts` stands right beside `components.js` what enables typed _subdirectory-style_ import. --- Additional changes: - Add "pack-dist" script to package.json I've been using it a lot, and I suppose it would be cool to download packed package with a GitHub Action or sth like that in Pull Requests.
I've fixed the conflict and rebased to v4. I didn't have time to get deep into v4 changes, but I love what I've seen already. Especially the |
@hasparus i am considering releasing v4, it's been in testing for a longer time now and the features are pretty good. should we take a longer time still for types or do you think it's all ready to go? |
It should be okay, though I’d probably test it again after the merge with v4 just in case. |
Connected issues: #172, #11, #10
Problem
Described in #172.
react-three-fiber types conflict with @types/react what forces users leveraging TypeScript type system to skip typechecking libraries.
Main change
I have removed
audio
andline
from IntrinsicElements interface.@types/react "was winning" and shadowing three-fiber
audio
andline
definitions, so they weren't usable for users with types for React.This is a small, but breaking change for people using react-three-fiber and react without @types/react, what is possible. I'm not sure how much of JavaScript projects would be affected, because VSCode automatic type acquisition can get @types/react for JavaScript users.
I've copycatted the lie from React Native and added
components
export with values typed asReact.FC<...>
, which are strings at runtime.It would be pretty cool to allow to
but I didn't want to complicate the PR.
More changes
Added jest to unit test
components
a bit.Removed @types/three, because it's deprecated. THREE ships its own types.
Disabled '@typescript-eslint/no-empty-interface'. This rule doesn't know if you extend a mapped type which is the case for ThreeFiberComponents.
yarn typecheck
didn't work for me 😔--emitDeclarationOnly false
to makenoEmit
work.Notes
I think
components.tsx
is a little bit more complicated than it has to be.We could map over THREE exports without losing type info (no Object.entries) and instead of type asserting entire dict
as any as ThreeFiberComponents
, assert string value to a function component with proper props.I'm not sure if I'm capable enough to simplify it soon :c
Deployed demo with my changes: