#Type hint not resolve to actual type

1 messages · Page 1 of 1 (latest)

cerulean relic
#

Not sure if it is related to TypeScript version or VSCode version, but I have this piece of code where getCache() return type will be the actual return type of createCache() using getCache(): ReturnType<this["createCache"]>.

It works fine for sometime, but I'm not sure when, the type hint for getCache() does not resolve to the actual type of the overrode createCache(), and showed as a plain ReturnType<this["createCache"]> instead of { name: string, age: number }.

Sample code:

abstract class CacheManager {
  getCache(): ReturnType<this['createCache']> {
    return this.createCache()
  }

  abstract createCache(): any
}

class MyCacheManager extends CacheManager {
  doSomething() {
    const cache = this.getCache()
    // should be { name: "John", age: 30 } or { name: string, age: number }
    // instead of ReturnType<this["createCache"]>
  }

  override createCache() {
    return { name: 'John', age: 30 }
  }
}
bleak hornet
#

This looks like its mainly just a display issue:

median owlBOT
#
michael#7468

Preview:```ts
abstract class CacheManager {
getCache(): ReturnType<this["createCache"]> {
return this.createCache()
}

abstract createCache(): any
}

class MyCacheManager extends CacheManager {
doSomething() {
const cache = this.getCache()
cache.a
...```

bleak hornet
#

it has the correct type

#

just the way the language server has chosen to represent it looks odd

cerulean relic
#

can I set it so that it resolve to the actual type? (like it was previously)

#

not sure where to look (TypeScript or VSCode settings)