0
在一個文件中,我有我的類實現..如何在另一個文件中使用類的類型?
// person.js
class Person {
...
}
在另一個文件,我想用這種類型的...
// job.js
class Job {
person: Person; // ERROR: Flow: identifier `Person`. Could not resolve name
/* @flow */
// person.js
type PersonOptions = {
status: string
}
class Person {
name: string;
options: PersonOptions;
constructor (name: string, optionalOptions: PersonOptions) {
this.name = name;
this.options = optionalOptions;
}
getStatus() {
console.log(`${this.name} is ${this.options.status}`);
}
}
// IN ANOTHER FILE
// job.js
class Job {
title: string;
person: Person; // ERROR: Flow: identifier `Person`. Could not resolve name
constructor (title: string, person: Person) {
this.title = title;
this.person = person;
}
getStatus() {
console.log(`${this.person.name} work with ${this.title}`);
}
}