interface Teacher {
name: string;
age: number;
address: {
city: string;
}
}
type ReadOnlyRecursive<T> = {
// 这里不是很能理解, 比如说传进去Teacher, P是name, 值类型就是ReadOnlyRecursive<Teacher["name"]>
// 即ReadOnlyRecursive<string>, 即
/*
{
[P in keyof string]: ReadOnlyRecursive<string[P]>
}
*/
// 但是实际上ReadOnlyRecursive<string> 就是string
[P in keyof T]: ReadOnlyRecursive<T[P]>;
}
一般来说递归是要有一个边界条件的, 这里的边界条件感觉很模糊