[英]ambient definition file not picked up by typescript
I am creating this sandbox and in ./src/components/tree/index.tsx
I have this code:我正在创建这个沙箱,在
./src/components/tree/index.tsx
我有这个代码:
/// <reference path="./Tree.d.ts" />
export const Tree: React.FunctionComponent<TreeProps> = ({
And in Tree.d.ts
I have the interface definition:在
Tree.d.ts
我有接口定义:
export interface TreeProps<Datum, LinkComponentType, NodeComponentType> {
top?: number;
left?: number;
But tsc is complaining:但是 tsc 抱怨:
Cannot find name 'TreeProps'.ts(2304) Exported variable 'Tree' has or is using private name 'TreeProps'.ts(4025)
找不到名称“TreeProps”.ts(2304) 导出的变量“Tree”具有或正在使用私有名称“TreeProps”.ts(4025)
You forgot to import the
interface
TreeProps
from your file.您忘记从文件中导入
interface
TreeProps
。
Just add the following line in your src/components/Tree/index.tsx
只需在
src/components/Tree/index.tsx
添加以下行
import {TreeProps} from './Tree'
You also need to pass arguments to the Tree props您还需要将参数传递给 Tree 道具
Here are a few things I would like you to know, maybe you already know some things here.这里有一些我想让你知道的事情,也许你已经在这里知道了一些事情。
The declaration file for the module in file abc.js
should be in abc.d.ts, the file name should be same and should be in the same directory, or you have to explicitly add declare module
in your declaration file.文件
abc.js
模块的声明文件应该在abc.d.ts中,文件名应该相同并且应该在同一个目录下,或者你必须在你的声明文件中明确添加declare module
。
Declaration files are used to tell the types of the javascript modules , so when you're writing typescript, you don't need to add .d.ts
file, tsc
will auto-generate .js
and corresponding .d.ts
files.声明文件是用来告诉javascript模块的类型的,所以在写
.d.ts
,不需要添加.d.ts
文件, tsc
会自动生成.js
和对应的.d.ts
文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.