I have a Vuejs project in Typescript. Project compiles and runs perfectly without error. But the TS linter is wrong.
I'm using the component decorator in individual component files like so:
//videocard.component.vue
<script lang="ts">
import Vue from 'vue';
import { Component, Prop } from 'vue-property-decorator';
import { Video } from '../interfaces/video.interface';
@Component
export default class VideoCardComponent extends Vue {
@Prop() readonly video: Video;
@Prop() readonly loading: boolean;
created(){
console.log(this.static_url); // !COMPLAINS HERE!
}
get _video(){
return this.video
}
get _loading(){
return this.loading || false;
}
}
</script>
Notice how I'm trying to log out property called static_url. This works because in my app.ts file, I'm setting this property like this:
//app.ts
Vue.prototype.static_url = (window as any).static_url;
I have augmented the types so static_url is a property on Vue. Like so:
// static_url.d.ts
import Vue from 'vue';
declare module 'vue/types/vue' {
interface Vue {
static_url: string;
}
interface VueConstructor {
static_url: string
}
}
Typescript linter does NOT complain about this property in the app.ts file, but it DOES complain about this property in the component files. Why does Typescript not recognize this property in the component files?
For completeness, here is my tsconfig.json file:
{
"compilerOptions": {
"target": "es5",
"lib": ["esnext", "dom"],
"strict": true,
"module": "es2015",
"noImplicitAny": false,
"moduleResolution": "node",
"experimentalDecorators": true,
"strictPropertyInitialization": false
},
"include": [
"assets/js/video-app/src/**/*.ts",
"assets/js/video-app/src/**/*.d.ts",
]
}