I have trouble importing vexflow in TypeScript.
I created an almost empty typescript project. I did `npm install vexflow`. This is package.json:
{
"name": "vexflow5_use_in_ts",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"vexflow": "^5.0.0"
}
}
This is tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"module": "es6",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": ["index.ts"]
}
This is index.ts:
import { StaveNote } from 'vexflow';
const note = new StaveNote({ keys: ['c/4'], duration: 'q' });
When I compile the TypeScript (`npx tsc`) I get this error:
index.ts:1:10 - error TS2305: Module '"vexflow"' has no exported member 'StaveNote'.
1 import { StaveNote } from 'vexflow';
I tried installing @types/vexflow but that didn't help, and I assume in 5.0 you don't need to do that (?)
I then tried
import vf from 'vexflow';
const note = new vf.StaveNote({ keys: ['c/4'], duration: 'q' });
and got this error:
index.ts:3:21 - error TS2339: Property 'StaveNote' does not exist on type 'typeof Vex'.
3 const note = new vf.StaveNote({ keys: ['c/4'], duration: 'q' });
I can get rid of the errors by doing this:
import vf from 'vexflow';
const vf2 = vf as any;
const note = new vf2.StaveNote({ keys: ['c/4'], duration: 'q' });
That works, but it feels awkward. Moreover I don't get code completions because of the type 'any'.
What am I doing wrong?