-
Notifications
You must be signed in to change notification settings - Fork 45
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
Typescript support #6
Comments
Hi @aVileBroker, i'm not an TS expert, so I would be very happy if you could point this out with an example? |
For the react-three-arjs specific type issues, obviously there are no type definitions so I have a lot |
I think you could develop type definitions for react-three-arjs as described in this guide https://www.typescriptlang.org/docs/handbook/declaration-files/dts-from-js.html but i never tried, so i can't assure that it's appliable in this case. |
Added ts declarations in a separate branch. @aVileBroker Would be happy if you can test if it works like this. |
Sweet! I'll check it out, thank you! |
@j-era @aVileBroker probably is better to move definitions in another folder and then add |
Updated types in 951e6b9 Think it should work like this @aVileBroker Did you try? |
Is there any progress on this? Can I assist somehow? |
Hello! Love this project ❤️ ! Chiming in to say the typescript support would be awesome Thanks for everything! |
EDIT: Not sure how to solve this. I cannot get this library to work with typescript 😞 I have tried using a custom typings file that uses the above types provided {
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"jsx": "react-jsx",
"lib": ["dom", "dom.iterable", "esnext"],
"module": "esnext",
"moduleResolution": "node",
"noEmit": true,
"noFallthroughCasesInSwitch": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"target": "es5",
"typeRoots": ["src/custom_typings", "node_modules/@types"]
},
"include": ["src"]
} The typincs file is in this location My type definitions import { Props } from "@react-three/fiber/dist/declarations/src/web/Canvas";
declare module "@artcom/react-three-arjs" {
export interface ARCanvasProps extends Props {
arEnabled?: boolean;
tracking?: boolean;
patternRatio?: number;
detectionMode?: string;
cameraParametersUrl?: string;
matrixCodeType?: string;
sourceType?: string;
onCameraStreamReady?: () => void;
onCameraStreamError?: () => void;
}
export interface ARMarkerProps {
children: React.ReactNode;
type: string;
barcodeValue?: string;
patternUrl?: string;
params?: Object;
onMarkerFound?: () => void;
onMarkerLost?: () => void;
}
export declare function ARCanvas(props: ARCanvasProps): JSX.Element;
export declare function ARMarker(props: ARMarkerProps): JSX.Element;
} But it just won't work. I have tried other type definitions such as an ambient type declaration for the types of this library. None of the works. @aVileBroker - Were you able to get this working? |
Hola, declare module "@artcom/react-three-arjs" {
import { WebGLRenderer } from "three";
import { CanvasProps } from "@react-three/fiber/dist/declarations/src/web/Canvas";
declare const ARCanvas = ({
children,
camera,
gl,
onCreated,
...props
}: {
children: ReactNode;
camera: { position: number[] };
gl: {
antialias: boolean;
powerPreference: string;
physicallyCorrectLights: boolean;
};
onCameraStreamReady: () => void;
onCameraStreamError: () => void;
onCreated: ({ gl }: { gl: WebGLRenderer }) => void;
} & CanvasProps) => JSX.Element;
declare const ARMarker = ({
children,
params,
type,
patternUrl,
}: {
children: ReactNode;
params: { smooth: boolean };
type: "barcode" | "hiro" | "pattern";
patternUrl: string;
onMarkerFound: () => void;
}) => JSX.Element;
} In addition to that I had some errors that went away dynamic importing the ArCanvas with |
Currently, using react-three-arjs is a bit frustrating in TS. The R3F Canvas needs to be imported (not used) to get the R3F JSX elements, and none of the components have the props accessible/defined. This codebase is pretty small so adding types should be fairly simple.
I'm happy to work on this and get a PR up for it if need-be!
The text was updated successfully, but these errors were encountered: