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

Clean TS install, View type errors. #130

Open
PButcher opened this issue May 5, 2023 · 8 comments
Open

Clean TS install, View type errors. #130

PButcher opened this issue May 5, 2023 · 8 comments

Comments

@PButcher
Copy link

PButcher commented May 5, 2023

After a clean install using yarn create r3f-app next app -ts, the View components in both app/page.tsx and app/blob/page.tsx show the following errors:

Type '{ children: Element; className: string; }' is not assignable to type 'IntrinsicAttributes & RefAttributes<unknown>'.
Property 'children' does not exist on type 'IntrinsicAttributes & RefAttributes<unknown>'.

Inside src/components/canvas/View.tsx the type errors above are present on the ForwardRef, as well as a type error on PerspectiveCamera.

The app still runs and does not output any errors to the terminal or browser console.

Node v16.14.2, MacOS v12.5.1

@vegancat
Copy link

vegancat commented May 13, 2023

Same Error with me, it's a eslint error. bumping next and next-eslint-config both to 13.4.0 solves some of problems but linting ones remain the same

@tunztunztunz
Copy link

I did what @vegancat suggested and it seemed to fix most of the errors with the View component except for the error @PButcher was saying they had. I was able to fix the errors with the View component by typing it like this:

interface ViewProps {
  children: ReactNode
  orbit?: boolean
  className?: string
}

I'm not sure if that's the best approach, but it seems to get rid of the ts error, at least.

@mystist
Copy link

mystist commented Jun 20, 2023

Same issue and even worse. This is supper horrible

@onion2k
Copy link

onion2k commented Jun 26, 2023

@tunztunztunz's suggestion resolved the View component problems for me.

Installing @types/three resolved all the type issues on the Three components.

I also needed to add a color prop to the first Common component.

@dsimonow
Copy link

dsimonow commented Jul 4, 2023

usePostprocess.tsx is also full of errors. even after updating next and next eslint.

@xih
Copy link

xih commented Jul 28, 2023

Running into a bunch of type errors as well with a fresh typescript install. installing @types/three didn't solve it for me.

any solutions?

image

@filahf
Copy link

filahf commented Aug 30, 2023

Running into a bunch of type errors as well with a fresh typescript install. installing @types/three didn't solve it for me.

any solutions?

The Common component should be typed like this:

type CommonProps = { color?: THREE.ColorRepresentation }

export const Common = ({ color }: CommonProps) => (...)

and the View component should be typed like this:

type ViewProps = HTMLAttributes<HTMLDivElement> & {
  orbit?: boolean
}

const View = forwardRef<HTMLElement, ViewProps>(({ children, orbit, ...props }, ref) => {..}

I would make a PR, but it seems like the ts flavored template is hidden.

@benschac
Copy link

From 4680864d804943e2d156735d722b306983fcfe3c Mon Sep 17 00:00:00 2001
From: benjamin <[email protected]>
Date: Wed, 24 Apr 2024 11:31:46 -0400
Subject: [PATCH] fix types in pagetsx

---
 src/components/canvas/View.tsx | 45 +++++++++++++++++++++-------------
 1 file changed, 28 insertions(+), 17 deletions(-)

diff --git a/src/components/canvas/View.tsx b/src/components/canvas/View.tsx
index ad5cd94..d0cb461 100644
--- a/src/components/canvas/View.tsx
+++ b/src/components/canvas/View.tsx
@@ -1,10 +1,10 @@
 'use client'
 
 import { forwardRef, Suspense, useImperativeHandle, useRef } from 'react'
-import { OrbitControls, PerspectiveCamera, View as ViewImpl } from '@react-three/drei'
+import { OrbitControls, PerspectiveCamera, View as ViewImpl, ViewProps } from '@react-three/drei'
 import { Three } from '@/helpers/components/Three'
 
-export const Common = ({ color }) => (
+export const Common = ({ color }: { color?: string }) => (
   <Suspense fallback={null}>
     {color && <color attach='background' args={[color]} />}
     <ambientLight />
@@ -14,22 +14,33 @@ export const Common = ({ color }) => (
   </Suspense>
 )
 
-const View = forwardRef(({ children, orbit, ...props }, ref) => {
-  const localRef = useRef(null)
-  useImperativeHandle(ref, () => localRef.current)
+const View = forwardRef(
+  (
+    {
+      children,
+      orbit,
+      ...props
+    }: ViewProps & {
+      orbit?: boolean
+    },
+    ref,
+  ) => {
+    const localRef = useRef(null)
+    useImperativeHandle(ref, () => localRef.current)
 
-  return (
-    <>
-      <div ref={localRef} {...props} />
-      <Three>
-        <ViewImpl track={localRef}>
-          {children}
-          {orbit && <OrbitControls />}
-        </ViewImpl>
-      </Three>
-    </>
-  )
-})
+    return (
+      <>
+        <div ref={localRef} {...props} />
+        <Three>
+          <ViewImpl track={localRef}>
+            {children}
+            {orbit && <OrbitControls />}
+          </ViewImpl>
+        </Three>
+      </>
+    )
+  },
+)
 View.displayName = 'View'
 
 export { View }
-- 
2.39.3 (Apple Git-145)

patch if it's helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants