Skip to content

Support for defining custom response type#193

Open
DalmasN wants to merge 1 commit into
sitevision:mainfrom
DalmasN:response-type
Open

Support for defining custom response type#193
DalmasN wants to merge 1 commit into
sitevision:mainfrom
DalmasN:response-type

Conversation

@DalmasN

@DalmasN DalmasN commented Mar 16, 2026

Copy link
Copy Markdown

Being able to define custom return types is useful and opens up for cleaner code. Currently the response is types as unknown and often leads the developer to using type assertions.

// Example with type assertions (current way)

type User = {
    id: string;
    name: string;
}

const [user, setUser] = useState<User|null>(null);

requester
    .doGet({
        url: router.getStandaloneUrl("/user"),
    })
    .then((userData) => {
        setUser(userData as User); // userData is unknown
    })
// Example using generics (proposed new way)

type User = {
    id: string;
    name: string;
}

const [user, setUser] = useState<User|null>(null);

requester
    .doGet<User>({
        url: router.getStandaloneUrl("/user"),
    })
    .then((userData) => {
        setUser(userData); // userData is of type User
    })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant