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.

generated JS uses type as value

See original GitHub issue

I opened https://github.com/vuejs/vue-cli/issues/1498 on vue-cli, but was redirected here.

Reproduction repo: https://github.com/doppelreim/vue-test-app/tree/test-import-route

Steps to reproduce: Run ./node_modules/.bin/vue-cli-service serve

Expected: The app should compile without warnings.

Actual: There are warnings:

 WARNING  Compiled with 4 warnings                                                                                                            09:41:30

 warning  in ./src/components/HelloWorld.vue?vue&type=script&lang=ts

"export 'Route' was not found in 'vue-router'

 warning  in ./src/components/HelloWorld.vue?vue&type=script&lang=ts

"export 'Route' was not found in 'vue-router'

 warning  in ./src/components/HelloWorld.vue?vue&type=script&lang=ts

"export 'Route' was not found in 'vue-router'

 warning  in ./src/components/HelloWorld.vue?vue&type=script&lang=ts

"export 'Route' was not found in 'vue-router'

The change that introduces the warnigns can be seen here: https://github.com/doppelreim/vue-test-app/commit/af036724ecbe53853ce10707796c82213ae07a43

I want to add a Watcher on $route. The parameters of the function (newRoute and oldRoute) should be typed. I assume Route is the correct type.

I checked out /node_modules/vue-router/types/index.d.ts and there Route does get exported, as far as I can tell.

If I use Route inside of the function-body, like this:

const r: Route = {
  path: '',
  hash: '',
  query: {},
  params: {},
  fullPath: '',
  matched: [],
};

then it does not throw errors. And if I leave out some of the required attributes, then the compiler rightfully complains. So I assume the export/import does work here.

@yyx990803 provided a technical explanation in https://github.com/vuejs/vue-cli/issues/1498#issuecomment-395461425 - but there is nothing vue-cli can do about it.

Not sure, where to address this. Maybe here?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
doppelreimcommented, Jun 29, 2018
1reaction
doppelreimcommented, Jun 29, 2018

Disabling emitDecoratorMetadata works. Nice!

It was initially enabled when I created the app with vue-cli. Do you know whether they do it only because of vue-property-decorator?

Read more comments on GitHub >

github_iconTop Results From Across the Web

typescript - How to generate value from type? - Stack Overflow
We need to use the as const assertion here to tell typescript that labels isn't an array of any ol' strings, it's an...
Read more >
Documentation - Creating Types from Types - TypeScript
In this section we'll cover ways to express a new type in terms of an existing type or value. Generics - Types which...
Read more >
typeof - JavaScript - MDN Web Docs - Mozilla
The typeof operator returns a string indicating the type of the operand's value.
Read more >
How To Create Custom Types in TypeScript - DigitalOcean
Though the basic types in TypeScript will cover many use cases, creating your own custom types based on these basic types will allow...
Read more >
TypeScript: How to get types from arrays - Steve Holgado
It can be useful to get a type from an array of values so that you can use it as, say, the input...
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