javascript - what is .d.ts file and why it is needed -
i'm reviewing source code angular-ui-router
, there angular-ui-router.d.ts
file inside api folder following content:
declare module ng.ui { interface istate { name?: string; template?: string; templateurl?: any; // string || () => string templateprovider?: any; // () => string || ipromise<string> } interface itypedstate<t> extends istate { data?: t; }
i've read file typescript type definitions. it? why needed?
it's declaration file:
when typescript script gets compiled there option generate declaration file (with extension .d.ts) functions interface components in compiled javascript. in process compiler strips away function , method bodies , preserves signatures of types exported. resulting declaration file can used describe exported virtual typescript types of javascript library or module when third-party developer consumes typescript.
the concept of declaration files analogous concept of header file found in c/c++.
Comments
Post a Comment