Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何从“.d.ts”文件导入?_Angular_Typescript - Fatal编程技术网

Angular 如何从“.d.ts”文件导入?

Angular 如何从“.d.ts”文件导入?,angular,typescript,Angular,Typescript,该线路在使用angular2 RC4的项目中工作 import*作为“../../../../node_modules/angular2 google maps/core/services/google maps types.d.ts”中的映射类型 发生了什么事 现在我正在使用RC6尝试一个新的种子文件,同一行给出了这个错误 错误TS2691:导入路径不能以“.d.ts”扩展名结尾。考虑导入'.///////NoDeDeMease/angal2谷歌映射/核心/服务/谷歌映射类型]。 但如果我做

该线路在使用angular2 RC4的项目中工作

import*作为“../../../../node_modules/angular2 google maps/core/services/google maps types.d.ts”中的映射类型

发生了什么事

现在我正在使用RC6尝试一个新的种子文件,同一行给出了这个错误

错误TS2691:导入路径不能以“.d.ts”扩展名结尾。考虑导入'.///////NoDeDeMease/angal2谷歌映射/核心/服务/谷歌映射类型]。

但如果我做出建议的改变,我会

找不到模块“../../../../node\u模块/angular2谷歌地图/core/services/google地图类型”

.d.ts
文件如下所示:

/**
 * angular2-google-maps - Angular 2 components for Google Maps
 * @version v0.12.0
 * @link https://github.com/SebastianM/angular2-google-maps#readme
 * @license MIT
 */
export declare var google: any;
export interface GoogleMap {
    constructor(el: HTMLElement, opts?: MapOptions): void;
    panTo(latLng: LatLng | LatLngLiteral): void;
    setZoom(zoom: number): void;
    addListener(eventName: string, fn: Function): void;
    getCenter(): LatLng;
    setCenter(latLng: LatLng | LatLngLiteral): void;
    getBounds(): LatLngBounds;
    getZoom(): number;
    setOptions(options: MapOptions): void;
}
...
/// <reference path="../../../../node_modules/angular2-google-maps/core/services/google-maps-types.d.ts"
匹配的
.ts
文件如下所示

/**
 * angular2-google-maps - Angular 2 components for Google Maps
 * @version v0.12.0
 * @link https://github.com/SebastianM/angular2-google-maps#readme
 * @license MIT
 */
"use strict";

//# sourceMappingURL=google-maps-types.js.map

注意:此软件包有一个与RC6匹配的较新版本,但我应该能够使它至少在TS中编译。通常在TypeScript中,您会在.TS文件顶部添加对定义文件的引用,如下所示:

/**
 * angular2-google-maps - Angular 2 components for Google Maps
 * @version v0.12.0
 * @link https://github.com/SebastianM/angular2-google-maps#readme
 * @license MIT
 */
export declare var google: any;
export interface GoogleMap {
    constructor(el: HTMLElement, opts?: MapOptions): void;
    panTo(latLng: LatLng | LatLngLiteral): void;
    setZoom(zoom: number): void;
    addListener(eventName: string, fn: Function): void;
    getCenter(): LatLng;
    setCenter(latLng: LatLng | LatLngLiteral): void;
    getBounds(): LatLngBounds;
    getZoom(): number;
    setOptions(options: MapOptions): void;
}
...
/// <reference path="../../../../node_modules/angular2-google-maps/core/services/google-maps-types.d.ts"

//如果您使用的是最新版本的TypeScript,并且键入定义嵌入到您的npm包中,那么您只需从模块导入:

import { GoogleMap } from 'angular2-google-maps/core/services/google-maps-types'
即使它是一个接口

事实上,您正在从
core/services/google maps types.js
导入定义,但此文件的存在只是为了提供与其
.d.ts
文件关联的定义

它的工作原理就像您直接从
.ts
文件导入一样,但由于您在npm模块中,它们嵌入定义文件以允许定义导入