Skip to content

constraint of type parameter should make effect in method declaration #61059

Closed as not planned
@bvanjoi

Description

@bvanjoi

🔎 Search Terms

"constraint", "method declaration"

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about "A method and a function property of the same type behave differently"

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.8.0-dev.20250127#code/JYOwLgpgTgZghgYwgAgIIB4AqA+ZBvAKGWRgHtT0BVZCAD0hABMBnZHACloC5lKBKHnBABPAgF8CBGAFcQCMMFIgSABnZweGZmCigA5tgA0yAEab0IaQFsT0bH3xFip5AF5kcZAHovyZgAtSaQAbRmQoCAAHUigwGigoGNNpOMQwaThg4OFkEFIwADpJZ1MCslJ2AEYHH2RZZiCmcUkgA

💻 Code

interface A<T> {
  foo<U extends T>(x: U): any
}

function f0(a: A<string>, b: A<number>) {
    b = a // should report error but actually not.

    b.foo(1) // unsound
}

🙁 Actual behavior

check success

🙂 Expected behavior

b = a report number cannot assign to string.

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions