Reputation: 451
Burning through a typescript course I came across these code pieces that fail to compile and give error TS2304. Any help is appreciated.
file ZooAnimals.ts:
namespace Zoo {
interface Animal {
skinType: string;
isMammal(): boolean;
}
}
File ZooBirds.ts:
/// <reference path="ZooAnimals.ts" />
namespace Zoo {
export class Bird implements Animal {
skinType = "feather";
isMammal() {
return false;
}
}
}
The command to compile the files:
tsc --outFile Zoo.js ZooAnimals.ts ZooBirds.ts
Throws error:
ZooBirds.ts:3:34 - error TS2304: Cannot find name 'Animal'.
3 export class Bird implements Animal {
Upvotes: 3
Views: 9705
Reputation: 249466
To use the interface across files (or more precisely across multiple namespace
declarations) it must be exported (even if it is part of the same namespace). This will work:
namespace Zoo {
export interface Animal {
skinType: string;
isMammal(): boolean;
}
}
namespace Zoo {
export class Bird implements Animal {
skinType = "feather";
isMammal() {
return false;
}
}
}
Upvotes: 2