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

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

问题描述

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天全站免登陆