question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Single type definition file for all vue files

See original GitHub issue

Right now, I need to create a type definition file for each .vue with the following contents:

import Vue = require('vue')

declare var exp: Vue
export default exp

Anyway I can just do with one *.vue.d.ts file?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
HerringtonDarkholmecommented, Feb 6, 2017

Adding a new ambient declaration.

declare module "*.vue"
1reaction
gldraphaelcommented, Feb 3, 2017

@gazugafan I got it working by making the vue-loader use vue-ts-loader to handle ts code. Here’s my webpack.config.js file.

  // ...
  vue: {
    // instruct vue-loader to load TypeScript
    loaders: { 
      js: 'vue-ts-loader', 
      less: 'css!less',
      ts: 'vue-ts-loader'
    },
    // make TS' generated code cooperate with vue-loader
    esModule: true
  },
  // ...

VS Code still shows the Cannot find module './path/to/file.vue'. for every .vue file.

But Webpack (and the dev console) shows this error

error TS2307: Cannot find module ‘./app.vue’.

only for the app.vue file. I’m yet to find what’s causing it. I’m guessing it’s got to do with webpack.config.js.

Good news is that, despite the errors the app works fine. So this should do for the time being.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Use TypeScript with Vue Single File Components
Step 1 — Setting Up the Project · Step 2 — Configuring the TypeScript Compiler · Step 3 — Using Basic and Custom...
Read more >
Single-File Components - Vue.js
Vue Single -File Components (a.k.a. *.vue files, abbreviated as SFC) is a special file format that allows us to encapsulate the template, logic, ......
Read more >
Subtle error when importing typescript definition file into vue file
I've seen this a few times. I think the right solution (given recent enough typescript, I'm using 4.1.3) is import type {Prop} from...
Read more >
Generate d.ts file for Vue components written in Typescript
This is a official tool from TypeScript(Microsoft). I used it with vue-blockui for generate de d.ts files and working.
Read more >
TSConfig Reference - Docs on every TSConfig option
ts files for every TypeScript or JavaScript file inside your project. These .d.ts files are type definition files which describe the external API...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found