Skip to content

Instantly share code, notes, and snippets.

@radiosilence
Last active April 21, 2017 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radiosilence/85878b976ba7c2ff7ff4502a690b08a2 to your computer and use it in GitHub Desktop.
Save radiosilence/85878b976ba7c2ff7ff4502a690b08a2 to your computer and use it in GitHub Desktop.
I am having a confuse about generics
interface Z {
potato: string
}
abstract class A<T> { // I want to indicate that T will always at least implement Z
protected foo(bar: T) {
console.log(bar.potato); // ERROR: [ts] Property 'potato' does not exist on type 'T'
}
}
class B extends A<Z> {
public bork() {
const z: Z = {
potato: 'tomato',
}
this.foo(z)
}
}
const b = new B();
b.bork()
// Should output: 'potato'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment