Typescript 流到类型脚本迁移
我尝试将尚未编写的项目从Flow迁移到TypeScript。 我有一些流结构,在TypeScript中找不到对应的流结构Typescript 流到类型脚本迁移,typescript,flowtype,Typescript,Flowtype,我尝试将尚未编写的项目从Flow迁移到TypeScript。 我有一些流结构,在TypeScript中找不到对应的流结构 type Value = | string | number | boolean | BaseObject | Array<BaseObject> type BaseObject = ObjectMap<?Value> & { meta?: BaseObject; } type ObjectMap<T>
type Value =
| string
| number
| boolean
| BaseObject
| Array<BaseObject>
type BaseObject = ObjectMap<?Value> & {
meta?: BaseObject;
}
type ObjectMap<T> = {
[key: string]: T;
};
类型值=
|串
|数
|布尔值
|基本对象
|排列
键入BaseObject=ObjectMap以下是(和等效项)
你能把你想复制的流程结构贴出来吗?你的意思是什么?我发布了导致错误的代码。是TypeScript代码还是Flow代码,还是两者都有?查看您尝试复制的流代码和您尝试复制的TypeScript代码会很有帮助。这就是流代码。我只是试着用tsc编译。嗯,是的,对不起。我已经改编了一些部分。我用原始代码更新了我的问题轻微改进:将ObjectMap
替换为Record
。没有必要为此引入额外的类型。
// The unchanged Flow type works in TypeScript.
type Value =
| string
| number
| boolean
| BaseObject
| Array<BaseObject>
// The unchanged Flow type works in TypeScript.
type ObjectMap<T> = {
[key: string]: T;
};
// The unchanged Flow type...
// type BaseObject = ObjectMap<?Value> & {
// meta?: BaseObject;
// }
// ...and the equivalent TypeScript.
interface BaseObject extends ObjectMap<Value | null | undefined> {
meta?: BaseObject;
}
const x: BaseObject = {
prop1: null,
prop2: undefined,
prop3: 'prop3',
prop4: 10,
prop5: {
meta: {}
},
prop6: [{
meta: {}
}],
prop7: new Date() // causes an error
}