itsfrank / vue-typescript

Typescript decorators to make vue feel more typescripty
MIT License
357 stars 25 forks source link

Cannot find namespace 'vuejs'. #7

Closed faisalhakim47 closed 8 years ago

faisalhakim47 commented 8 years ago

am I doing something wrong?

this is my tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "moduleResolution": "node",
    "target": "es5",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true
  }
}

screenshot from 2016-07-27 10-33-53

itsfrank commented 8 years ago

Do you have typings setup?

make sure to install typings and the vue type definititons like so:

$npm install --save-dev typings
$typings install --save --global dt~vue

In addition, in your ts config:

if using exclude, dont exclude your typings if using include, make sure to include typings/index.d.ts

itsfrank commented 8 years ago

Closing this for now, let me know if you have any additional issues

faisalhakim47 commented 8 years ago

it does work after I added vuejs typings globally. Is that how it supposed to work? screenshot from 2016-07-29 05-28-11

itsfrank commented 8 years ago

yes exactly, normally you would search before installing though ;)

vue, vue-router, and vue-resource (not up to date unfourtunately, you need to add the json() function manually after you install it) all have typings on definitley typed. And i think vuex has typing in the repo. Check out the great seed project by @danielschmitz here for vuex and more: https://github.com/danielschmitz/awesome-vue-typescript

I also made a barebones/minimal typing for vuestrap here: https://github.com/itsFrank/vue-typescript/issues/9

for other vue plugins you can make your own quick typings for the functions you use, or else just cast them as , its ugly and not good practice, but it saves you some time for the odd feature that's not typed and you use very rarely. For example, in one project i used the jquery plugin select2 only once, so i didn't bother adding the typing to the jquery definitions, i simply did this: (<any>$('#my-element')).select2(); so that the ts compiler wouldn't complain.

itsfrank commented 8 years ago

for vue-resource just add a file called 'index.d.ts' to a folder called 'typings_manual/vue-resource' in your project root containing this:

declare namespace vuejs {
    interface HttpResponse {
        blob():Blob,
        json():any,
        text():string
    }
}

I'll probably be making a pull request on the repo soon though

itsfrank commented 8 years ago

Ive submitted a pr to dt for vue-resource: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/10349 hopefully it gets merged soon