You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using Typescript 2.7.1, importing Vue 2.5.13 results in undefined.
To reproduce, create a blank .ts file:
import Vue from "vue";
console.log(Vue); // <-- will be `undefined` (or `null` in Code Sandbox)
This can be fixed by importing like:
import * as Vue from "vue";
... but then new Vue() returns the TS error:
test.ts (3,1): Cannot use 'new' with an expression whose type lacks a call or construct signature. (2351)
Changing this to new Vue.default(); resolves the TS error, but then results in a Node error:
TypeError: Vue.default is not a constructor
What is expected?
No errors
What is actually happening?
See above
Note: I'm not using Webpack in this example. What I assume is happening (referencing the recommended tsconfig.json config) is that import statements are being as-is by Typescript, for Webpack to pick up and use properly.
However, I think that this should be improved to work with Typescript directly, without requiring Webpack to enter the mix. This would benefit server-only environments where code transpilation isn't necessarily required.
The text was updated successfully, but these errors were encountered:
@leebenson Just want to say, thanks for the revelation! I have consistently experienced issues with webpack + TypeScript not resolving imports properly, and it turns out that using import * as Vue from "vue"; works, while import Vue from "vue" actually returns null: https://codesandbox.io/s/mjvjw2xw39
Version
2.5.13
Reproduction link
https://codesandbox.io/s/4895o6nm24
Steps to reproduce
Using Typescript 2.7.1, importing Vue 2.5.13 results in
undefined
.To reproduce, create a blank .ts file:
This can be fixed by importing like:
... but then
new Vue()
returns the TS error:Changing this to
new Vue.default();
resolves the TS error, but then results in a Node error:What is expected?
No errors
What is actually happening?
See above
Note: I'm not using Webpack in this example. What I assume is happening (referencing the recommended
tsconfig.json
config) is thatimport
statements are being as-is by Typescript, for Webpack to pick up and use properly.However, I think that this should be improved to work with Typescript directly, without requiring Webpack to enter the mix. This would benefit server-only environments where code transpilation isn't necessarily required.
The text was updated successfully, but these errors were encountered: