Skip to content

Use generic return types for frequently-casted library functions #18415

Closed
@RyanCavanaugh

Description

@RyanCavanaugh

There are a handful of functions from lib.d.ts which are typically followed by a type assertion

const x = <HTMLDivElement>document.getElementById('zzz');

With the new inference changes, we can write a new overload

getElementById<T extends Element>(id: string): T

so that you can write the cleaner version

const x: HTMLDivElement = document.getElementById('zzz');

TODO: Figure out which functions these apply to

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeclinedThe issue was declined as something which matches the TypeScript visionDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions