是否可以在 VSCode(或其他地方)中显示打字稿类型/接口的完整计算类型 [英] Is it possible to display the full computed type of a typescript type/interface in VSCode (or elsewhere)

查看:22
本文介绍了是否可以在 VSCode(或其他地方)中显示打字稿类型/接口的完整计算类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您将鼠标悬停在 VSCode 中的类型上时,它会显示该类型,但如果您有更大的类型,它通常会将其显示为 { a: string;……还有 24 个……;z:字符串}.是否有可能让它以某种方式显示完整类型?

When you hover over a type in VSCode it shows the type, but if you have a larger type it usually displays it as { a: string; ... 24 more ...; z: string }. Is it possible to get it to display the full type somehow?

同样,如果您有两种类型的交集,那么有时它只会将其显示为 Type1 &Type2 而不是显示完整类型,或者如果您使用 Pick 那么它将显示 Pick...

Similarly, if you have an intersection of two types then sometimes it will just display it as Type1 & Type2 instead of displaying the full type, or if you use the Pick then it will display Pick<Type1, "a" | ... 23 more ... | "z">...

在所有这些情况下,我认为检查我对打字稿正在做什么的理解会很有用,以便有时能够看到完整的类型,并且想知道是否有办法做到这一点,无论是通过 vscode 还是以某种方式通过打字稿的工具.

In all of these cases I think it would be useful to check my understanding of what typescript is doing to be able to see the full type sometimes and was wondering if there was a way to do that, whether through vscode or somehow through typescript's tools.

推荐答案

不,没有.然而,最新版本的 TS 确实比以前更好.当我对类型进行故障排除时,我会使用一些技巧来解开复杂的类型.

No, there isn't. However the latest release of TS does make this better than it was before. When I am troubleshooting types I use a few techniques to unravel complex types.

最重要的是为您要检查的属性创建类型.然后您可以在对象中建立索引以检查类型.不理想,但简单快捷.

The biggest on is to create types for the properties you are trying to inspect. Then you can index in the object to inspect the types. Not ideal, but easy, and fast.

const object1 = { a1: 4, b1: "test", c1: true, d1: ["test", "test2"], e1: { ea1: "yes", eb1: 3, ec1: [4] } as const } as const;
const object2 = { a2: 4, b2: "test2", c2: false, d1: ["testw", "testw2"], e2: { ea2: "no", eb2: 5, ec2: [8] } as const } as const;
const object3 = { a3: 4, b3: "test", c3: true, d3: ["test", "test2"], e3: { ea3: "never", eb3: 3, ec3: [4] } as const } as const;
const object4 = { a4: 4, b4: "test2", c4: false, d4: ["testw", "testw2"], e4: { ea4: "maybe", eb4: 5, ec4: [8] } as const } as const;
type testComplexType = typeof object1 & typeof object2 & typeof object3 & typeof object4;

type whatTypeIsThis = testComplexType["e1"]["ea1"]; //yes
type whatTypeIsThis2 = testComplexType["e2"]["ea2"]; //no
type whatTypeIsThis3 = testComplexType["e3"]["ea3"]; //never
type whatTypeIsThis4 = testComplexType["e4"]["ea4"]; //maybe

这篇关于是否可以在 VSCode(或其他地方)中显示打字稿类型/接口的完整计算类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆