如何访问模块内的TypeScript定义?

我想input一些在NodeJS定义中描述的'Url'对象。 但'Url'对象在'url'模块下描述。 因为它在模块之下,所以它不被编译器识别为有效的types。

///<reference path='../../../Definitions/node.d.ts' /> ///<reference path='../../../Definitions/node-webkit.d.ts' /> ///<reference path='../../../Definitions/cheerio.d.ts' /> var NodeUrl = require('url'); function findLinks($cheerio:Cheerio, internalOnly?:boolean, rootUrl?:url.Url):string[] { //url.Url is not recognised, neither is Url or NodeUrl.Url } 

定义文件定义了以下模块(与NodeJS的其余部分一起):

 declare module "url" { export interface Url { href: string; protocol: string; auth: string; hostname: string; port: string; host: string; pathname: string; search: string; query: any; // string | Object slashes: boolean; hash?: string; path?: string; } export interface UrlOptions { protocol?: string; auth?: string; hostname?: string; port?: string; host?: string; pathname?: string; search?: string; query?: any; hash?: string; path?: string; } export function parse(urlStr: string, parseQueryString?: boolean , slashesDenoteHost?: boolean ): Url; export function format(url: UrlOptions): string; export function resolve(from: string, to: string): string; } 

如何正确引用Urltypes?

谢谢你的帮助。

在打字稿中,您需要使用稍微不同的语法来导入模块:

 import NodeURL = require('url'); 

你现在可以访问

 NodeURL.Url