tweakpane / use-tweaks

🎛️ Tweak React components with Tweakpane
https://codesandbox.io/s/use-tweaks-example-58e02
MIT License
768 stars 23 forks source link

`useTweaks` type not working #38

Closed ivanross closed 3 years ago

ivanross commented 3 years ago

Description

useTweaks return type is always any.

Example


const tweaks = useTweaks({ first: 10 }) // has type any

https://codesandbox.io/s/usetweaks-type-issue-1k2lo

gsimone commented 3 years ago

@ivanross useTweaks should be used as a generic, the signature is

export function useTweaks<T extends Schema>(schema: T, settings?: Settings): UseTweaksValues<T>

So

  const tweaks = useTweaks<{ first: number }>({ first: 10 });

I do agree that it doesn't seem to be working, though

@dbismut I remember this was working in the examples, could it be a problem with the npm bundle?

ivanross commented 3 years ago

Hi @gsimone thank you for the quick answer!

I see that useTweaks is generic, and if you check the codesandbox it seems that Typescript understands it

image

dbismut commented 3 years ago

Hi guys, I don't know what's happening... This is what I get in the example from the repo, maybe there's something wrong when bundling types as you're saying GM... We're using TypeScript 4, not sure if this has an impact but even upgrading @ivanross sandbox didn't seem to solve it...

image

But in any case:

// you shouldn't be using the shouldn't need to do this
const tweaks = useTweaks<{ first: number }>({ first: 10 });

// this should work instead
const tweaks = useTweaks({ first: 10 });
ivanross commented 3 years ago

@gsimone @dbismut Just opened a PR to solve this!