pixijs / pixi-react

Write PIXI apps using React declarative style
https://pixijs.io/pixi-react/
MIT License
2.36k stars 178 forks source link

Bug: `<text>` component throws type errors #500

Closed trezy closed 3 months ago

trezy commented 3 months ago

Current Behavior

The <text> component throws a type error when using the text property.

Expected Behavior

The <text> component does not throw a type error when using the text property.

Steps to Reproduce

<text text={'text'} />

Environment

Possible Solution

No response

Additional Information

I'm pretty confident the issue is the order of overloads on the Text constructor in Pixi.js. When we're dynamically building the types for Pixi React, we can't choose which overload to use. I think Typescript is just picking the last overload (which is deprecated) by default. This overload doesn't accept TextOptions as the first property like most other classes, so it doesn't expose the appropriate props on the <text> copmponent.

https://github.com/pixijs/pixijs/blob/dev/src/scene/text/Text.ts#L40-L46

trezy commented 3 months ago

Fixed in 8.0.0-dev.6b268b5.

utenma commented 1 month ago

On v9.beta13 react treats text tags as React.SVGTextElementAttributes<SVGTextElement> image

tried to override the default type for JSX.IntrinsicElements.tex but cannot resolve PixiReactElementProps type

declare namespace JSX {
    interface IntrinsicElements {
        ['text']: PixiReactElementProps<typeof Text>
    }
}
utenma commented 1 month ago

@trezy fixed adding the following pixi.d.ts file to project

// pixi.d.ts
declare namespace JSX {
    interface IntrinsicElements {
        "text": import('pixi.js').TextOptions
    }
}

is it worth including it on v9? it types correctly text on JSX like pixiText