sandrozbinden
sandrozbinden

Reputation: 1607

io-ts Object Typename is lost in WebStorm

I would like to use io-ts in order to validate input. However compared to an interface type the WebStorm/IDEA does not show the name of the object type when hovered over the type but shows the details of the type itself.

Lets assume we have the following code a io-ts User and a Interface User.

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 }

When I hover over myUserI the type information show from WebStorm is const myUserI: UserI

Object Typename Interface

However when I hover over the myUserIoTs type the information show from WebStorm is const myUserIoTs: {name: string;} instead of const myUserIoTs:User

Object Typename io-ts

Is there a way that WebStorm can show the type name User instead of {name: string}?

Upvotes: 1

Views: 207

Answers (2)

sandrozbinden
sandrozbinden

Reputation: 1607

There is a workarround for this by defining an interface.

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

Upvotes: 0

lena
lena

Reputation: 93828

The tooltip you see in WebStorm when you ctrl+ hover over a symbol in a TypeScript file shows the inferred type info from the TypeScript compiler service. And there's indeed a known difference in the information TypeScript itself provides for interfaces and enums vs type aliases. Here's an issue on the TypeScript's tracker: https://github.com/microsoft/TypeScript/issues/25894

Upvotes: 2

Related Questions