IDE类型推断错误,test方法会飘红,但是test2方法不会

下方代码,IDE类型推断错误,test方法会飘红,但是test2方法不会,从代码上看,接口声明入参其实是一致的,理论上要么都报错,要么都不报错

import { ExcludeKey } from '../ts/Omit' 
 
interface AA { 
  name: string 
} 
 
interface BB { 
  age: number 
} 
 
type CC = ExcludeKey<BB, keyof AA> 
 
function test(c: CC) { 
  console.log(c.age.toString()) 
} 
 
function test2(c: ExcludeKey<BB, keyof AA>) { 
  console.log(c.age.toString()) 
} 
 
test({ age: 123 }) 
 
test2({ age: 123 })
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
HarmonyOS
2024-04-28 00:37:09
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
superinsect

这个问题,当前报错,是语法规范问题,虽然两种类型,开发者中代码层面看,入参是一样的,但是对于IDE的语法扫描,将他们解析成对应的语法树是不一样的。 type类型,当前不支持属性交叉,要求需要使用类或者接口替换。 对于下面这种方式,语法规则,暂时没有定义,所以不会扫描报错

分享
微博
QQ
微信
回复
2024-04-28 21:41:55
相关问题
HarmonyOS window.findWindow("test")问题
618浏览 • 1回复 待解决
HarmonyOS 单元测试Local Test 问题
1367浏览 • 1回复 待解决
比如 test(param1:'test)?
3273浏览 • 1回复 待解决
打包包含ohosTest文件夹和test文件夹吗
1637浏览 • 1回复 待解决
获取当前设备类型方法
1248浏览 • 1回复 待解决