-
Notifications
You must be signed in to change notification settings - Fork 48
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
Enhance exported types #66
Comments
Yes we should export the return types as well. I did not realize it at first, but it seems like we cannot extract the proper return type since we cannot specific the generic value for the function. Right now doing type LocalStorageReturnValue = ReturnType<typeof useLocalStorage>; yields type LocalStorageReturnValue = [unknown, (newValue: unknown) => void, () => void] TypeScript doesn't let us do: Type LocalStorageReturnValue = ReturnType<typeof useLocalStorage<string>>; // syntax error and I don't believe there is anyway to make that generic https://stackoverflow.com/questions/50321419/typescript-returntype-of-generic-function |
Added return types in 2b85b87 |
Amazing! Thanks 🚀 |
How would I be able to import the return type for export type LocalStorageNullableReturnValue<TValue> = [TValue | null, (newValue: TValue | null) => void, () => void];
export type LocalStorageReturnValue<TValue> = [TValue, (newValue: TValue | null) => void, () => void]; from it was exported in use-localstoreage.ts but was not exported in index.ts, I am only able to import from index.ts. |
Public method parameters and return types could be exported too, so when wrapping then in another method it is possible to specify return types.
Example:
In this case, I had to copy the return signature. If
LocalStorageHook
was exported as a type from the library, this wouldn't be necessary. :)Pro-tip: when using
@microsoft/api-extractor
this already becomes a code smell, and automatically generate markdown/DocFX docsPro-tip 2: In LocalStorageHook we create a type for each tuple member, like [StorageValue, WriteStorage,DeleteFromStorage], it enhances the documentation too o/
I may help with PRs if you will.
The text was updated successfully, but these errors were encountered: