Wrap Final Typsecript Export In Module?
I have a bunch of models and services which I need to export within a TS module. Source models/User.ts import {IModel} from './IModel'; export interface User extends IModel {
Solution 1:
It seems like typings bundle
does exactly what you need. It will combine all your declaration files and dependencies into one file.
Let's say eg. I have an module called "stackoverflow" that has two files (stackoverflow.ts and constants.ts). index.ts depends on both an external library (eg. bluebird) and constants.ts.
stackoverflow.ts
import { PromisifyOptions } from'bluebird'export { FIRST } from'./constants'exportinterface thePromiseUsingInterface {
options: PromisifyOptions
}
constants.ts
exportconst FIRST = 1exportconst SECOND = 2
To generate the master declaration file:
- generate your declaration files :
tsc --delcaration
) - bundle the declaration files and their dependencies into index.d.ts:
typings bundle -o index.d.ts
When you publish your library to npm, make sure to also include your typings.json.
In your other project, you can then npm install stackoverflow
and start using it:
import * as constants from'stackoverflow/constants'console.log(constants.SECOND)
For reference here is a gist with all the relevant files: stackoverflow.ts, constants.ts, index.d.ts, package.json, typings.
Post a Comment for "Wrap Final Typsecript Export In Module?"