MST

星途 面试题库

面试题:TypeScript类型查询操作符之Extract的应用

假设有两个类型 `T = { a: string; b: number; c: boolean; }` 和 `U = { a: string; d: number; }`,请使用 `Extract` 类型查询操作符提取出 `T` 中与 `U` 共有的属性类型,并编写相应的TypeScript代码实现。
30.8万 热度难度
前端开发TypeScript

知识考点

AI 面试

面试题答案

一键面试
type T = { a: string; b: number; c: boolean; };
type U = { a: string; d: number; };
type CommonProps = Extract<keyof T, keyof U>;
type CommonPropsType = {
    [K in CommonProps]: T[K];
};