Skip to content

Relax the rule on the compiler side that all declarations have the same constraint #20018

Closed
@mhegazy

Description

@mhegazy

Originally reported in #14840

Consider WeakSet for instance.. today it is defined as interface WeakSet <T> {...}. This is incorrect, as it allows for patterns like const s = new WeakSet<string>(); s.add("foo"); which throws at runtime; the correct definition for WeakSet is interface WeakSet<T extends object> { .. }.

Changing this definition will cause errors in files that redefine WeakSet to add additional members to it.

Error: All declarations of WeakSet must have identical type paramters

The proposal here is to allow type parameter declarations to skip constraints. conflicting constraints should still be reported as errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    CommittedThe team has roadmapped this issueFixedA PR has been merged for this issueGood First IssueWell scoped, documented and has the green lightHelp WantedYou can do thisSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions