Skip to content

TypeScript Generics #13

Open
Open

Description

@dimadeveatii

Should we cover generics?

Activity

  1. badsyntax commented on Jan 13, 2022

    @badsyntax

    While T might be acceptable when only one generic is used, things get out of hand when multiple generics are used, and i've see people use T,U,D etc which is completely meaningless IMO.

    Even the typescript docs now use description generic names: https://www.typescriptlang.org/docs/handbook/2/generics.html

    function identity<Type>(arg: Type): Type {
      return arg;
    }

    Example of hard-to-read code due to single character generics: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/64d939eb39dc7b80b27da1a63774cfca755670f9/types/styled-components/index.d.ts

    Example of easy-to-read code due to descriptive generic names: https://github.com/tannerlinsley/react-query/blob/755702dd78efadb66038fb2535b7c513c128a918/src/react/useQuery.ts

    As a consumer of both of these types, it's so much easier to work with descriptive generic names.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions