34 lines
No EOL
918 B
TypeScript
34 lines
No EOL
918 B
TypeScript
// @target: es5
|
|
// @declaration: true
|
|
// There's a 'File' class in the stdlib, wrap with a namespace to avoid collision
|
|
namespace Test {
|
|
export class FileSystemObject {
|
|
isFSO: this is FileSystemObject;
|
|
get isFile(): this is File {
|
|
return this instanceof File;
|
|
}
|
|
set isFile(param) {
|
|
// noop
|
|
}
|
|
get isDirectory(): this is Directory {
|
|
return this instanceof Directory;
|
|
}
|
|
isNetworked: this is (Networked & this);
|
|
constructor(public path: string) {}
|
|
}
|
|
|
|
export class File extends FileSystemObject {
|
|
constructor(path: string, public content: string) { super(path); }
|
|
}
|
|
export class Directory extends FileSystemObject {
|
|
children: FileSystemObject[];
|
|
}
|
|
export interface Networked {
|
|
host: string;
|
|
}
|
|
|
|
let file: FileSystemObject = new File("foo/bar.txt", "foo");
|
|
file.isNetworked = file.isFile;
|
|
file.isFSO = file.isNetworked;
|
|
file.isFile = file.isFSO;
|
|
} |