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
The React definitions allow for calling useState with no initialState, and it will infer a state of type T | undefined. In Preact I must pass in an undefined as the initialState, and create a union with undefined for the type.
Describe the bug
The type definitions for useState differ slightly.
React: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/index.d.ts#L913
Preact: https://github.com/preactjs/preact/blob/master/hooks/src/index.d.ts#L10
The React definitions allow for calling useState with no initialState, and it will infer a state of type T | undefined. In Preact I must pass in an undefined as the initialState, and create a union with undefined for the type.
Preact valid code:
To Reproduce
const [editingObject, setEditingObject] = useState<{ id: number }>();
Expected behavior
This should compile and infer a state of type { id: number } | undefined
The text was updated successfully, but these errors were encountered: