mweststrate / use-st8

Single-function alternative for React.useState
MIT License
234 stars 7 forks source link

Create templated type for return value #7

Closed JoshuaKGoldberg closed 3 years ago

JoshuaKGoldberg commented 4 years ago

Thanks for this library, it's really nifty!

I'd like to represent an object containing st8 values (is that the right nomenclature?), but ReturnType<typeof useSt8> isn't syntactically allowed to include a <T> generic value.

type St8Number= ReturnType<typeof useSt8<number>>;
// '>' expected.ts(1005)

I'd be happy to send a PR that splits out a standalone type returned by useSt8:

export type St8<T> = {
    (): T;
    (newValue: T | ((current: T) => T)): void;
};

export default function useSt8<T>(i: (() => T) | T): St8<T>;
mweststrate commented 4 years ago

Feel free to open a PR :)