1e41f4b71Sopenharmony_ci# ArkCompiler Subsystem Changelog 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci## cl.arkcompiler.1 TS Compiler Targets ECMAScript 2021, Upgrading from ECMAScript 2017 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci**Access Level** 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ciOther 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci**Reason for Change** 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ciIn the OpenHarmony SDK, the **target** option of the TypeScript compiler is changed from ES2017 to ES2021. 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci**Change Impact** 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ciIn rare scenarios where the code uses ES2018-ES2021 syntax features with syntax errors, which are masked using the @ts-nocheck or @ts-ignore comment: 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ciBefore the change, these syntax errors are masked using comments, and the compilation is successful. 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ciAfter the change, the check rules for these syntaxes are enhanced, and a compilation error may be reported. 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci**Start API Level** 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci9 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci**Change Since** 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ciOpenHarmony SDK 5.0.0.19 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci**Key API/Component Changes** 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ciN/A 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci**Adaptation Guide** 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ciDelete the @ts-nocheck and @ts-ignore comments and perform adaptation based on the compilation error messages. Refer to the examples below. 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci1. ES2018 Feature: **rest** Property 39e41f4b71Sopenharmony_ci ``` 40e41f4b71Sopenharmony_ci // @ts-ignore 41e41f4b71Sopenharmony_ci const {a, ...remaning, b} = {a: 1, b: 2, c: 3, d: 4}; 42e41f4b71Sopenharmony_ci // ~~~~~~~~ 43e41f4b71Sopenharmony_ci // Masked error: A rest element must be last in a destructuring pattern. 44e41f4b71Sopenharmony_ci ``` 45e41f4b71Sopenharmony_ci Suggestion: Delete the @ts-ignore comment and place the **rest** property at the end. 46e41f4b71Sopenharmony_ci ``` 47e41f4b71Sopenharmony_ci const {a, b, ...remaning} = {a: 1, b: 2, c: 3, d: 4}; 48e41f4b71Sopenharmony_ci ``` 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci2. ES2020 Feature: Optional Chaining Operator 51e41f4b71Sopenharmony_ci ``` 52e41f4b71Sopenharmony_ci const object = { property: "hi" }; 53e41f4b71Sopenharmony_ci // @ts-ignore 54e41f4b71Sopenharmony_ci object?.property = "hello"; 55e41f4b71Sopenharmony_ci // ~~~~~~~~~~~~~ 56e41f4b71Sopenharmony_ci // Masked error: The left-hand side of an assignment expression may not be an optional property access. 57e41f4b71Sopenharmony_ci ``` 58e41f4b71Sopenharmony_ci Suggestion: Delete the @ts-ignore comment, check whether the object is null, and then assign a value. 59e41f4b71Sopenharmony_ci ``` 60e41f4b71Sopenharmony_ci const object = { property: "hi" }; 61e41f4b71Sopenharmony_ci if (object !== undefined) { 62e41f4b71Sopenharmony_ci object.property = "hello"; 63e41f4b71Sopenharmony_ci } 64e41f4b71Sopenharmony_ci ``` 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ci3. ES2020 Feature: Nullish Coalescing Operator 67e41f4b71Sopenharmony_ci ``` 68e41f4b71Sopenharmony_ci // @ts-nocheck 69e41f4b71Sopenharmony_ci let a = null || undefined ?? "foo"; 70e41f4b71Sopenharmony_ci // ~~~~~~~~~~~~~~~~~ 71e41f4b71Sopenharmony_ci // Masked error: '||' and '??' operations cannot be mixed without parentheses. 72e41f4b71Sopenharmony_ci let b = true && undefined ?? "foo"; 73e41f4b71Sopenharmony_ci // ~~~~~~~~~~~~~~~~~ 74e41f4b71Sopenharmony_ci // Masked error: '&&' and '??' operations cannot be mixed without parentheses. 75e41f4b71Sopenharmony_ci ``` 76e41f4b71Sopenharmony_ci Suggestion: Delete the @ts-nocheck comment and add parentheses to ensure that the operation sequence meets the expectation. 77e41f4b71Sopenharmony_ci ``` 78e41f4b71Sopenharmony_ci let a = (null || undefined) ?? "foo"; 79e41f4b71Sopenharmony_ci let b = (true && undefined) ?? "foo"; 80e41f4b71Sopenharmony_ci ``` 81e41f4b71Sopenharmony_ciFor other scenarios with incompatible changes, delete the @ts-nocheck and @ts-ignore comments and rectify the fault based on the compilation error messages. 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ciYou can also set **targetESVersion** to **ES2017** in the project-level **build-profile.json5** file to continue using ECMAScript 2017. 84