首页 > 解决方案 > io-ts 对象类型名称在 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

对象类型名 io-ts

WebStorm 有没有办法显示类型名称User而不是{name: string}

标签: typescriptwebstorm

解决方案


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


推荐阅读