演示代码:[https://tsplay.dev/N5jo0m](https://link.segmentfault.com/?enc=xHYb14bIdHYJJf7BB1mfxQ%3D%3D.BRY0g6o%2BeQRtsuvL7KvGNHIJl0SnBJWXvkTyq3IjR%2Fc%3D) interface Base { name: string; age: number; }; interface FixedInstance extends Base {} interface FollowInstance extends Base {} type NameType = "fixed"|"follow"; type FixedName = "fixed"; type FollowName = "follow"; const data: NameType = 'fixed'; type myType = typeof data; type isFixed = myType extends FixedName ? true : false; // true type isFollow = myType extends FollowName ? true : false; // false // -----------cut--- function sellect(name: T, data: U) { return { name, data }; } const { name: myName, data: myData } = sellect("fixed", { name: "levi", age: 18 } as FollowInstance); type dataType = typeof myData; type dataisFixed = myType extends FixedName ? true : false; // true type dataisFollow = myType extends FollowName ? true : false; // false 从`cut`以上,可以看到都是正确的,问题在函数`sellect` * 我需要根据第一个参数`name: T`去判断第二个参数`data`的类型 * 提供的`name`是`fixed`就限制`data`是`FixedInstance`,否则就限制为`FollowInstance` 问题1:我在`sellect`参数传参的时候故意` as FollowInstance`,在TS中并没有报错 问题2:在拿到的结果中`dataisFixed`是`true`,但是我传过去的是`FollowInstance`