![](/img/trans.png)
[英]Is there a way to use a npm package without d.ts definition on TypeScript
[英]typescript make a simple d.ts file for npm package
我正在嘗試聲明一個.d.ts文件以在agular 2應用程序中使用npm uuid 。 我正在做的事情似乎與我發現的示例一致,但出現錯誤: typescript d.ts file has no exported members v1
uuid / v1.d.ts文件:
declare var v1: any;
declare module "uuid/v1" {
export = v1;
}
npm js文件是uuid / v1.js :
function v1(options, buf, offset) { //...}
module.exports = v1;
我也嘗試過:
export = uuid;
declare namespace uuid {
function v1(): any;
}
這給出了運行時異常:
ORIGINAL EXCEPTION: __webpack_require__.i(...) is not a function
我假設這將與我編寫DefinitelyTyped文件的方式類似。 請參閱@ types / selenium-webdriver 。
declare namespace uuid {
interface V1Options {
/**
* Node id as Array of 6 bytes (per 4.1.6).
* Default: Randomly generated ID.
*/
node?: Array<any>;
/**
* Number between 0 - 0x3fff. RFC clock sequence.
* Default: An internally maintained clockseq is used
*/
clockseq?: number;
/**
* Time in milliseconds since unix Epoch.
* Default: The current time is used.
*/
msecs: number|Date;
/**
* Number between 0-9999) additional time, in 100-nanosecond units.
* Ignored if msecs is unspecified. Default: internal uuid
* counter is used, as per 4.2.1.2.
*/
nsecs: number;
};
/**
* Generate and return a RFC4122 v1 (timestamp-based) UUID.
* @param {V1Options} options Optional uuid state to apply.
* @param {Array<any>|Buffer} buffer Array or buffer where
* UUID bytes are to be written.
* @param {number} offset Starting index in buffer at which to begin writing.
*/
v1(options?: V1Options, buffer?: Array<any>|Buffer, offset?: number): Buffer;
}
export = uuid;
我相信您必須指示tsconfig.json
使用此文件(或將其發布到DefinitelyTyped),然后才能import {v1, V1Options} from 'uuid';
或import * from 'uuid';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.