You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
According to the NPM document, useTexture accepts two kinds of input, which is string | string[]. However, on version 2.2.15, the type for useTexture is useTexture(url: string): Texture | Texture[], which is causing a constraint of inputting string[] and outputting only Texture or Texture[].
For example, the following code is reporting a type error.
consttexture=useTexture('/asset/stacy.jpg');return(<group><primitiveobejct={object}<skinnedMesh{...props}><meshStandardMaterialmap={texture}/>// texture doesn't match `map` property because it only accepts `Texture`, and the type for texture is `Texture | Texture[]`.</skinnedMesh></group>)
In conclusion, useTexture should be generic, output Texture when the input is string, and output Texture[] when the input is string[].
Package Version
typescript: 4.1.3
three: 0.124.0
@react-three/drei: 2.2.15
react-three-fiber: 5.3.11
The text was updated successfully, but these errors were encountered:
I also ran into this problem #176. I did a little digging and I think the current typing for url argument is always evaluating to a non array value. There is probably a more elegant TS solution out there, but this fixed it for me locally:
Current: (string type would never extend any[]) useTexture(url: string extends any[] ? string[] : string): Texture | Texture[];
The following snippet is from @react-three/drei#useTexture.
According to the NPM document,
useTexture
accepts two kinds of input, which isstring | string[]
. However, on version2.2.15
, the type foruseTexture
isuseTexture(url: string): Texture | Texture[]
, which is causing a constraint of inputtingstring[]
and outputting onlyTexture
orTexture[]
.For example, the following code is reporting a type error.
In conclusion,
useTexture
should be generic, outputTexture
when the input isstring
, and outputTexture[]
when the input isstring[]
.Package Version
The text was updated successfully, but these errors were encountered: