#why typescript lies?

1 messages · Page 1 of 1 (latest)

torpid topazBOT
#
ricmed#0

Preview:```ts
interface Comply {
method1(): string
}

function fn1(x: Comply) {
return x.method1()
}

class Methods2<V> {
method1<V>(this: User<V>) {
return this.v
}
}

type User<T> = {
v: T
name: string
}

let obj1 = {v: 58, name: "john"} as User<number> &
Methods2<number>
...```

random hare
#

Because the <V> of Methods2 method1 shadows the one of the class

weak gate
#

sorry, what do you mean?

random hare
#
class Methods2<V> { // <-- V is declared here

//        |-------- // This declares another V
  method1<V>(this: User<V>) {
    return this.v
  }
}

It's the same as if you did:

class Methods2<V> { // <-- V is declared here

//        |-------- // This declares another V
  method1<X>(this: User<X>) {
    return this.v
  }
}
dry ravine
#

Hello I have quick questions related to types can I ask here

random hare
#

@dry ravine If it's complicated, maybe you should create a new thread, you know better 🙂

dry ravine
random hare
#

No clue :/

dry ravine
#

I ask in there support server as they don't know about it

weak gate
#

@random hare 🤦‍♂️ me. thanks!