After extending a class from an npm package with additional type definitions, I noticed that my custom definitions are taking lower priority than the ones coming from node_modules. Is there a way to adjust the TypeScript definition priority using the typeRoots property?
For instance, I extended the VueRouter
class from the vue-router
package in the following manner:
export class Router extends VueRouter {
pushWithCheck (location: RawLocation): Promise<Route | void> {
return this.push(location)
.catch((error: Error) => {
if (error && error.name !== 'NavigationDuplicated') {
throw error
}
})
}
}
I then created a file at src/@types/vue.d.ts
with the contents:
import Vue from 'vue'
import { Router } from '../router'
export {}
declare module 'vue/types/vue' {
interface Vue {
$router: Router
}
}
Next, I updated the tsconfig.json
file and added
typeRoots: ["./src/@types", "./node_modules/@types"]
(I also tried in reverse order).
In VS Code, this is what I observe: