Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type parameters as constraints dosen't work for methods #7079

Closed
hayeah opened this issue Feb 14, 2016 · 1 comment
Closed

Type parameters as constraints dosen't work for methods #7079

hayeah opened this issue Feb 14, 2016 · 1 comment
Labels
By Design Deprecated - use "Working as Intended" or "Design Limitation" instead

Comments

@hayeah
Copy link

hayeah commented Feb 14, 2016

PR #5949 implements F-bounded polymorphism. It doesn't seem to be working correctly for methods.

interface Table<T> {
  // For this method `T` is apparently a brand new type parameter.
  insert<T extends U, U>(obj: U): T;
  // insert(obj: any)
}

interface Foo {
  a: string;
  b: string;
}

let Foos: Table<Foo>;

// `foo1`'s type is inferred to be {a: 1}
let foo1 = Foos.insert({a: 1}) // => ;

// Should produce error
let foo2 = Foos.insert({c: 1});
@ahejlsberg
Copy link
Member

This is by design. As you mention in your comment, your insert method introduces a new (and unused) type parameter called T that is constrained to extend U, but there is no constraint on U itself. I'm guessing you're trying to express that U must be a supertype of T. That's not currently possible, but there is some discussion of that issue in #6613.

@ahejlsberg ahejlsberg added the By Design Deprecated - use "Working as Intended" or "Design Limitation" instead label Feb 14, 2016
@hayeah hayeah closed this as completed Feb 15, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
By Design Deprecated - use "Working as Intended" or "Design Limitation" instead
Projects
None yet
Development

No branches or pull requests

2 participants