io-ts 对象类型名称在 WebStorm 中丢失

io-ts Object Typename is lost in WebStorm

我想使用 io-ts 来验证输入。 但是,与接口类型相比,WebStorm/IDEA 将鼠标悬停在类型上时不显示对象类型的名称,而是显示类型本身的详细信息。

假设我们有以下代码,一个 io-ts 用户和一个接口用户。

import * as t from 'io-ts';

const UserType = t.type({
    name: t.string,
});

type User = t.TypeOf<typeof UserType>;

interface UserI {
    name: string;
}
const myUserI: UserI = { name: 'Paul' }; //WebStorm Type const myUserI: UserI
const myUserIoTs: User = { name: 'Luna' }; //WebStorm Type const myUserIoTs: { name : string }

当我将鼠标悬停在 myUserI 上时,WebStorm 显示的类型信息是 const myUserI: UserI

然而,当我将鼠标悬停在 myUserIoTs 类型上时,WebStorm 显示的信息是 const myUserIoTs: {name: string;} 而不是 const myUserIoTs:User

WebStorm 是否可以显示类型名称 User 而不是 {name: string}

当您 ctrl+ 将鼠标悬停在 TypeScript 文件中的符号上时,您在 WebStorm 中看到的工具提示显示了来自 TypeScript 编译器服务的推断类型信息。 TypeScript 本身为接口和枚举与类型别名提供的信息确实存在已知差异。这是 TypeScript 跟踪器的一个问题:https://github.com/microsoft/TypeScript/issues/25894

通过定义一个接口可以解决这个问题。

interface User extends t.TypeOf<typeof User> {}