Skip to content

generic for fetch solution does not work in the official playground #31

Open
@hazartilirot

Description

@hazartilirot

The provided code in the video does not seem to be working.

https://github.com/total-typescript/typescript-generics-workshop/blob/main/src/02-passing-type-arguments/11-data-fetcher.solution.ts

If you take the code and paste it into Typescript playground (I have done it for you) - you will get a bunch of errors.

The solution is as following:

const fetchData = async <T>(url: string): Promise<T> => await fetch(url).then(resp => resp.json as T)

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