“作为"是什么意思?关键字呢? [英] What does the "as" keyword do?

查看:36
本文介绍了“作为"是什么意思?关键字呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

if (process.env.NODE_ENV !== 'production') {
    (WithUser as any).displayName = wrapDisplayName(Component, 'withUser');
}

我什至不确定 as 是否是一个关键字,但无论如何,它在 JavaScript 中有什么作用?

I'm not even sure if as is a keyword, but anyway, what does it do in JavaScript?

推荐答案

那不是普通的 JavaScript,而是 TypeScript.无论如何,将类型化对象视为普通的非类型化 JavaScrpt 对象.

That is not vanilla JavaScript, it is TypeScript. As any means consider the typed object as a plain untyped JavaScrpt object.

as 关键字是一个 TypeScript 中的类型断言 告诉编译器将对象视为另一种类型,而不是编译器推断出的对象类型.

The as keyword is a Type Assertion in TypeScript which tells the compiler to consider the object as another type than the type the compiler infers the object to be.

这篇关于“作为"是什么意思?关键字呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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