Choices is not a constructor in TypeScript (Vue)
See original GitHub issueI am receiving this error Error in mounted hook: "TypeError: choices_js_1.default is not a constructor"
when trying to instantiate Choices in TypeScript.
Here’s how my component looks like:
<template>
</template>
<script lang="ts">
import Vue from 'vue';
import Choices from 'choices.js'
import {Component, Prop} from 'vue-property-decorator';
@Component
export default class Select extends Vue
{
@Prop({'default': null})
public name:string;
@Prop({'default': () => []})
public options:Array<any>;
@Prop({'default': null})
public selected:any;
public mounted()
{
let choices = new Choices('div');
}
}
</script>
Do you have any idea why?
Issue Analytics
- State:
- Created 6 years ago
- Comments:7
Top Results From Across the Web
Vue is not a constructor error, using Typescript & webpack
You want to use this one, since you are using it as an ES module with the import statement. Your alias should be:...
Read more >TypeError: "x" is not a constructor - JavaScript - MDN Web Docs
The JavaScript exception "is not a constructor" occurs when there was an attempt to use an object or a variable as a constructor,...
Read more >Typescript and Vue in general · Issue #478 · vuejs/vue - GitHub
Pass configuration to instance not via constructor. TypeScript class instances create members after the call to super and thus creates a subtle timing...
Read more >How To Write Class-Based Components with Vue.js and ...
In this article, you will be introduced to using vue-class-component and vue-property-decorator to support TypeScript in Vue.js class-based ...
Read more >Polls: Components and Vuex | learn-nuxt-ts
Choice [] ) { this.choices = choices !== undefined ? choices ... For lazy people like me, feel free to add a link...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Oh yes!!! Changing
module
toes6
did the trick and I am able now to make imports like:I will google now the differences in
module
property to get know a bit more what’s happening under the hood.Thank you very much!
The whole console log error below:
Ok I know the solution:
I had to import Choices like this:
import * as Choices from 'choices.js'
This one fails in my project
import Choices from 'choices.js'
I am not sure why, anyway now it works.