patterntypescriptCritical
What does the "as" keyword do?
Viewed 0 times
whatdoesthekeyword
Problem
if (process.env.NODE_ENV !== 'production') {
(WithUser as any).displayName = wrapDisplayName(Component, 'withUser');
}
I'm not even sure if
as is a keyword, but anyway, what does it do in JavaScript?Solution
That is not vanilla JavaScript; it is TypeScript.
The
as any tells the compiler to consider the typed object as a plain untyped JavaScript object.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.Context
Stack Overflow Q#55781559, score: 340
Revisions (0)
No revisions yet.