Typescript Dart中的递归对象类型?
我应该注意到,我来自一个打字脚本的背景,这给我的透视图/术语增添了很多色彩 在TypeScript中,您可以非常轻松地定义递归接口:Typescript Dart中的递归对象类型?,typescript,dart,recursive-type,Typescript,Dart,Recursive Type,我应该注意到,我来自一个打字脚本的背景,这给我的透视图/术语增添了很多色彩 在TypeScript中,您可以非常轻松地定义递归接口: interface User { name: string, friends: User[] } const bob:User = { name: "Bob", friends: [] } 在Dart中您将如何执行此操作?解决方案没有太大不同 class User { String name; List<User> frie
interface User {
name: string,
friends: User[]
}
const bob:User = {
name: "Bob",
friends: []
}
在Dart中您将如何执行此操作?解决方案没有太大不同
class User {
String name;
List<User> friends;
}
void main() {
var bob = User();
bob.name = "Bob";
bob.friends = [User(), User(), User()];
print(bob.name); // Bob
print(bob.friends); // [Instance of 'User', Instance of 'User', Instance of 'User']
}
类用户{
字符串名;
列出朋友;
}
void main(){
var-bob=User();
bob.name=“bob”;
bob.friends=[User(),User(),User()];
打印(bob.name);//bob
打印(bob.friends);//[用户实例,'用户'实例,'用户'实例]
}
这很有道理。我不习惯以类为中心的方法来处理类型,也不习惯默认的可空性。谢谢