简体   繁体   English

打字稿多文件名称空间导出错误

[英]typescript multi-file namespaces export error

"You can split a namespace across many files. Even though the files are separate, they can each contribute to the same namespace and can be consumed as if they were all defined in one place. Because there are dependencies between files, you will add reference tags to tell the compiler about the relationships between the files." “您可以将一个名称空间拆分为多个文件。即使文件是分开的,它们也可以构成同一个名称空间,并且可以像在一个地方定义它们一样使用它们。因为文件之间存在依赖关系,所以您将添加引用标签来告知编译器文件之间的关系。”

//ZooAnimals.ts

namespace Zoo { 
    interface Animal { 
         skinType: string;
        isMammal(): boolean;
    }
}

//ZooWild.ts

/// <reference path="ZooAnimals.ts" />
namespace Zoo {
    export class Reptile implements Animal {//Error: Cannot find Animal
         skinType ="scales";
        isMammal(){
            return false;
        }
    }
}

why it shows "Error: Cannot find Animal"? 为什么显示“错误:找不到动物”?

This is because you do not export your interface properly. 这是因为您没有正确导出接口。 You left accidentally out the keyword export . 您不小心遗漏了关键字export Do it as follows: 如下进行:

namespace Zoo { 
    export interface Animal { 
         skinType: string;
        isMammal(): boolean;
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM