返回类型为decared的函数时,有一个snipet没有错误。
type Human = { head: number body: number } const human: Human = { head: 1, body: 1, } const humanFn: (human: Human) => Human = (human) => { return { // ...human, head: human.head, body: human.body, tail: 1, // allows illegal props } } humanFn({ ...human, tail: 1, // here is and error })
所以问题是为什么TS允许添加额外的道具来返回对象 tail: 1, // allows illegal props
tail: 1, // allows illegal props
升级版本:
https://github.com/microsoft/TypeScript/issues/241
以及将返回对象包装为 R.identity<Human>(...)
R.identity<Human>(...)
你的代码没有抛出编译错误,
function humanFn(human: Human): Human { return { // ...human, head: human.head, body: human.body, tail: 1, // Error } }
下面的代码也会抛出编译错误
const humanFn: (human: Human) => Human = (human): Human => { return { // ...human, head: human.head, body: human.body, tail: 1, // Error } }
你的问题似乎是另一种情况 this question .
the issue 在GitHub,就是关于这个问题。在里面 简称: 失控递归和/或性能
the issue 在GitHub,就是关于这个问题。在里面 简称:
失控递归和/或性能