Wednesday, 20 February 2019

Importing Victor.js in TypeScript?

I'm trying to use the victor.js library in a TypeScript project (3.0.1) and I'm having real heartache trying to import and use it. I've installed it from npm along with it's typings (victor @types/victor). I've tried to import it a myriad of ways but can't seem to get it to import along with type resolution in my IDE.

I've tried these:

import { Victor} from 'victor';  
import * as v from 'victor'; 

(This module can only be referenced with ECMAScript imports/exports by turning on the 'allowSyntheticDefaultImports' flag and referencing its default export)

import Victor = require('victor');  

(works but not compatible when targeting ecmascript modules)

const Victor = require("victor");  

(Imports validly and I can construct objects but none of the typings are present)

I'm sure someone out there has run into a similar situation to this before. If it helps the top of the index.js of victor has the line:

exports = module.exports = Victor;



from Importing Victor.js in TypeScript?

No comments:

Post a Comment