Skip to content

useDefault types #292

@DerHumm3l

Description

@DerHumm3l

Hi, I used the useDefault hook in my project with typescript in strict mode and had a little issue with the types returned by useDefault.

If I write the following code

import { useDefault } from "@uidotdev/usehooks";

function getInitialFoo(): string | null {
  return null;
}

export function App() {
  const initalFoo = getInitialFoo();
  const [foo, setFoo] = useDefault(initalFoo, "default");
}

then foo is string | null.

image

I would expect foo to be string since the passed default value is a string. So I was wondering if the types for useDefault are correct? Or am I missing something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions