通过打字稿课程燃烧,我遇到了无法编译并给出错误ts2304的这些代码件。任何帮助都将不胜感激。
文件Zooanimals.ts:
namespace Zoo {
interface Animal {
skinType: string;
isMammal(): boolean;
}
}
文件zoobirds.ts:
/// <reference path="ZooAnimals.ts" />
namespace Zoo {
export class Bird implements Animal {
skinType = "feather";
isMammal() {
return false;
}
}
}
编译文件的命令:
tsc --outFile Zoo.js ZooAnimals.ts ZooBirds.ts
引发错误:
ZooBirds.ts:3:34 - error TS2304: Cannot find name 'Animal'.
3 export class Bird implements Animal {
必须在文件上使用该接口(或更准确地说是多个namespace
声明),它必须导出(即使它是同一名称空间的一部分)。这将有效:
namespace Zoo {
export interface Animal {
skinType: string;
isMammal(): boolean;
}
}
namespace Zoo {
export class Bird implements Animal {
skinType = "feather";
isMammal() {
return false;
}
}
}