Fix class properties declarations #16386
Labels
squad:core
Issue to be handled by the Core team.
type:improvement
This issue reports a possible enhancement of an existing feature.
Milestone
As part of #16292, we plan to update our codebase to transpile to a valid ES2022 code (but still target
es2019
in TypeScript for the time being). To catch bugs early, we should also update esbuild (which we use for our test environment) to the latest version, which was blocked by the issues described in #14703.Let's take this code as an example:
TypeScript and
[email protected]
(which we currently use) will transpile this to the following:However, the newer versions of esbuild and swc will transpile the same code to the following if the
target
is set toES2021
or lower:When the
target
is set toES2022
, it's transpiled to:Unlike the first case,
Test.prototype.test
is declared when a new instance ofTest
is created. This is a problem in places where we are checking for the existence of a class property.This can be fixed by using Typescript's
declare
keyword, which tells it that the given property exists and what type it is, but doesn't add the property to the class.Updated source code:
Output:
The text was updated successfully, but these errors were encountered: