I have following package.json
:
{
"name": "browserify-test",
"version": "1.0.0",
"description": "",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
"build:tsc": "tsc --outDir dist",
"build:browser": "browserify src/index.ts -p tsify --standalone MyLib > dist/myLib.js"
},
"devDependencies": {
"browserify": "^14.0.0",
"tsify": "^3.0.0",
"typescript": "^2.1.5"
}
}
Following tsconfig.json
:
{
"compilerOptions": {
"noImplicitAny": true,
"module": "commonjs",
"target": "ES5",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"declaration": true
}
}
File src/evets.d.ts
:
export interface MyEvent {
name: string
}
And finally entry point src/index.js
:
import * as events from './events';
export class MyLibrary {
public test(eventInstance: events.MyEvent) {
console.log(eventInstance);
console.log(events);
}
}
Building pure typescript version works. So command npm run build:tsc
works perfectly but trying to build with browserify, so invoking npm run build:browser
i get following error:
> browserify-test@1.0.0 build /home/aszmyd/tmp/browserify-test
> browserify src/index.ts -p tsify --standalone MyLib > dist/myLib.js
Error: Cannot find module './events' from '/home/aszmyd/tmp/browserify-test/src'
It seems that browserify cannot properly consume type definition files with d.ts
extension.
The above example WORKS in two cases:
When in
index.ts
i import like this:import * as events from './events.d;
(note the ending .d)When i remove the
console.log(events);
line (?!) - how it can useevents.***
types but cannot use the whole set (alias) ?
I think im missing something dummy here but im lack of ideas.