手动添加声明文件(TypeScript) [英] Adding declarations file manually (TypeScript)

查看:346
本文介绍了手动添加声明文件(TypeScript)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有找到'google-spreadsheet'的声明文件,因此我试图自己创建一个声明文件:

I didn't find a declaration file for 'google-spreadsheet' so I'm trying to create one by myself:

在打字"->模块中,我添加了一个名为"google-spreadsheet"的新文件夹,并在其中添加了一个名为"index.d.ts"的新文件,其内容如下:

in typings -> modules, I've added a new folder named "google-spreadsheet", and there I've added a new file named "index.d.ts" which has the following content:

export class GoogleSpreadsheet {

}

在客户端文件中,我有这个:

In the client file I have this:

import * as GoogleSpreadsheet from 'google-spreadsheet';

但是'google-spreadsheet'用红色标记,表示:

But 'google-spreadsheet' is marked with red, saying:

TS2307找不到模块"google-spreadsheet".

TS2307 Cannot find module 'google-spreadsheet'.

顺便说一句,我已经NPM安装了"google-spreadsheet",并且可以使用JavaScript.这里只有TypeScript困扰我.

BTW I've NPM-installed 'google-spreadsheet' and it works JavaScriptly. Only the TypeScript bothers me here.

有什么办法解决这个问题吗?

Any ideas how to solve that?

推荐答案

如果您不需要关心此模块中的类型,则只能创建一个*.d.ts文件并放入以下内容(例如,创建Types.d) .ts):

If you dont need to care about the typings inside this module you can only create a *.d.ts file and put the following content (e.g. create a typings.d.ts):

declare module 'google-spreadsheet';

要在模块内定义类型,可以将以上代码更改为:

To define the types inside the module you can change the above code to:

declare module 'google-spreadsheet' {
    // define the types...
}

这篇关于手动添加声明文件(TypeScript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆