microsoft / TypeScript-Vue-Starter

A starter template for TypeScript and Vue with a detailed README describing how to use the two together.
MIT License
4.45k stars 592 forks source link

"Go to definition" on vue components goes to vue.d.ts #45

Open ubershmekel opened 6 years ago

ubershmekel commented 6 years ago

Repro steps:

  1. Clone and npm install this repo
  2. Open index.ts in VS code
  3. Right-click then select Go to Definition on HelloComponent
  4. VS Code opens vue.d.ts. When going to the definition of "./components/Hello.vue" I'm taken to vue-shims.d.ts instead.

Is this a known issue?

Atuna commented 6 years ago

Same here. And I have done some search, I am not sure is this relevant?

This is quite weird, since "Go to definition" works perfectly well in *.vue files. 2018-05-04 15 10 15

ubershmekel commented 6 years ago

@octref or @HerringtonDarkholme is this a Vetur bug?

HerringtonDarkholme commented 6 years ago

is this a Vetur bug?

Nope, Vetur cannot handle "jump to definition" in *.ts file.

"Go to definition" works perfectly well in *.vue files.

Vetur can handle definition lookup in vue file, but it cannot hijack the behavior of TS.

I'm taken to vue-shims.d.ts instead.

This is expected. Instead of using vue-shims.d.ts, you can try this TS server plugin. https://github.com/HerringtonDarkholme/vue-ts-plugin

I didn't invest much time in it, but it can handle basic definition lookup as far as I tried.

ubershmekel commented 6 years ago

Thanks @HerringtonDarkholme ! I'll test that in a bit. I wonder if jumping from a module to its source versus jumping to its type definition is worth supporting in the module declaration syntax itself somehow. @weswigham because you worked on https://github.com/Microsoft/TypeScript/issues/6209 I thought you might be able to weigh in.

weswigham commented 6 years ago

In 2.9 the language service will support reading sourcemaps for .d.ts files to map the results back into another file; that won't help here, though, since the problem arises from how imports from "*.vue" files have a wildcarded definition to a single type in the vue .d.ts. As far as TS is concerned, the .vue files aren't in the build - that's all the vue service (which is probably why it works from vue file to vue file, but not on imports in TS).

riddla commented 5 years ago

I just wanted to chime in here to say that https://github.com/HerringtonDarkholme/vue-ts-plugin works like a charm for "jump to definition" in VS Code.

Thanks @HerringtonDarkholme 👍