From 52ee9575e4d110769ac34c54554ebbba588a3bdd Mon Sep 17 00:00:00 2001 From: liujia178 Date: Sun, 28 Apr 2024 21:15:12 +0800 Subject: [PATCH] add TS5.0's feature Issue:https://gitee.com/openharmony/third_party_typescript/issues/I9HHI4 Test:ts extra test Signed-off-by: liujia178 --- .../all_enums_are_union_enums_1.ts | 44 +++++++++++ .../all_enums_are_union_enums_10.ts | 38 +++++++++ .../all_enums_are_union_enums_2.ts | 41 ++++++++++ .../all_enums_are_union_enums_3.ts | 41 ++++++++++ .../all_enums_are_union_enums_4.ts | 53 +++++++++++++ .../all_enums_are_union_enums_5.ts | 36 +++++++++ .../all_enums_are_union_enums_6.ts | 53 +++++++++++++ .../all_enums_are_union_enums_7.ts | 34 ++++++++ .../all_enums_are_union_enums_8.ts | 29 +++++++ .../all_enums_are_union_enums_9.ts | 40 ++++++++++ .../const_type_parameters_1.ts | 30 +++++++ .../const_type_parameters_10.ts | 38 +++++++++ .../const_type_parameters_2.ts | 30 +++++++ .../const_type_parameters_3.ts | 30 +++++++ .../const_type_parameters_4.ts | 30 +++++++ .../const_type_parameters_5.ts | 31 ++++++++ .../const_type_parameters_6.ts | 30 +++++++ .../const_type_parameters_7.ts | 30 +++++++ .../const_type_parameters_8.ts | 30 +++++++ .../const_type_parameters_9.ts | 36 +++++++++ .../5.0/decorators/decorators_1.ts | 41 ++++++++++ .../5.0/decorators/decorators_10.ts | 37 +++++++++ .../5.0/decorators/decorators_2.ts | 46 +++++++++++ .../5.0/decorators/decorators_3.ts | 47 +++++++++++ .../5.0/decorators/decorators_4.ts | 52 +++++++++++++ .../5.0/decorators/decorators_5.ts | 49 ++++++++++++ .../5.0/decorators/decorators_6.ts | 49 ++++++++++++ .../5.0/decorators/decorators_7.ts | 37 +++++++++ .../5.0/decorators/decorators_8.ts | 36 +++++++++ .../5.0/decorators/decorators_9.ts | 54 +++++++++++++ ...cit_coercions_in_relational_operators_1.ts | 26 +++++++ ...it_coercions_in_relational_operators_10.ts | 31 ++++++++ ...cit_coercions_in_relational_operators_2.ts | 26 +++++++ ...cit_coercions_in_relational_operators_3.ts | 26 +++++++ ...cit_coercions_in_relational_operators_4.ts | 26 +++++++ ...cit_coercions_in_relational_operators_5.ts | 31 ++++++++ ...cit_coercions_in_relational_operators_6.ts | 31 ++++++++ ...cit_coercions_in_relational_operators_7.ts | 31 ++++++++ ...cit_coercions_in_relational_operators_8.ts | 31 ++++++++ ...cit_coercions_in_relational_operators_9.ts | 31 ++++++++ .../overload_support_in_jsdoc_1.ts | 52 +++++++++++++ .../overload_support_in_jsdoc_10.ts | 51 ++++++++++++ .../overload_support_in_jsdoc_2.ts | 47 +++++++++++ .../overload_support_in_jsdoc_3.ts | 49 ++++++++++++ .../overload_support_in_jsdoc_4.ts | 52 +++++++++++++ .../overload_support_in_jsdoc_5.ts | 52 +++++++++++++ .../overload_support_in_jsdoc_6.ts | 52 +++++++++++++ .../overload_support_in_jsdoc_7.ts | 78 +++++++++++++++++++ .../overload_support_in_jsdoc_8.ts | 68 ++++++++++++++++ .../overload_support_in_jsdoc_9.ts | 74 ++++++++++++++++++ .../satisfies_support_in_jsdoc_1.ts | 44 +++++++++++ .../satisfies_support_in_jsdoc_10.ts | 39 ++++++++++ .../satisfies_support_in_jsdoc_2.ts | 30 +++++++ .../satisfies_support_in_jsdoc_3.ts | 29 +++++++ .../satisfies_support_in_jsdoc_4.ts | 38 +++++++++ .../satisfies_support_in_jsdoc_5.ts | 39 ++++++++++ .../satisfies_support_in_jsdoc_6.ts | 49 ++++++++++++ .../satisfies_support_in_jsdoc_7.ts | 32 ++++++++ .../satisfies_support_in_jsdoc_8.ts | 31 ++++++++ .../satisfies_support_in_jsdoc_9.ts | 38 +++++++++ .../support_for_export_type/models/factory.ts | 35 +++++++++ .../support_for_export_type/models/index.ts | 21 +++++ .../models/vehicles.ts | 35 +++++++++ .../support_for_export_type/shap/circle.ts | 24 ++++++ .../5.0/support_for_export_type/shap/index.ts | 21 +++++ .../support_for_export_type/shap/square.ts | 23 ++++++ .../support_for_export_type_1.ts | 33 ++++++++ .../support_for_export_type_10.ts | 31 ++++++++ .../support_for_export_type_11.ts | 53 +++++++++++++ .../support_for_export_type_12.ts | 40 ++++++++++ .../support_for_export_type_2.ts | 27 +++++++ .../support_for_export_type_3.ts | 38 +++++++++ .../support_for_export_type_4.ts | 33 ++++++++ .../support_for_export_type_5.ts | 34 ++++++++ .../support_for_export_type_6.ts | 30 +++++++ .../support_for_export_type_7.ts | 42 ++++++++++ .../support_for_export_type_8.ts | 36 +++++++++ .../support_for_export_type_9.ts | 39 ++++++++++ 78 files changed, 3001 insertions(+) create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_1.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_10.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_2.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_3.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_4.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_5.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_6.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_7.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_8.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_9.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_1.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_10.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_2.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_3.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_4.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_5.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_6.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_7.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_8.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_9.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_1.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_10.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_2.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_3.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_4.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_5.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_6.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_7.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_8.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_9.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_1.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_10.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_2.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_3.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_4.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_5.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_6.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_7.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_8.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_9.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_1.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_10.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_2.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_3.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_4.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_5.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_6.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_7.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_8.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_9.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_1.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_10.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_2.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_3.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_4.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_5.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_6.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_7.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_8.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_9.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/models/factory.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/models/index.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/models/vehicles.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/shap/circle.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/shap/index.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/shap/square.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_1.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_10.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_11.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_12.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_2.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_3.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_4.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_5.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_6.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_7.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_8.ts create mode 100644 tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_9.ts diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_1.ts b/tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_1.ts new file mode 100644 index 0000000000..08c8ab4da3 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_1.ts @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 5.0 manages to make all enums into union enums by creating a unique type for each computed member. + module: ES2022 + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +enum Color { + Red, + Orange, + Yellow, + Green, + Blue, + Violet +} + +type PrimaryColor = Color.Red | Color.Green | Color.Blue; + +function isPrimaryColor(c: Color): c is PrimaryColor { + return (c === Color.Red || c === Color.Green || c === Color.Blue); +} + +const blueColor = isPrimaryColor(Color.Blue); +Assert.isTrue(blueColor); + +const yellowColor = isPrimaryColor(Color.Yellow); +Assert.isFalse(yellowColor); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_10.ts b/tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_10.ts new file mode 100644 index 0000000000..dd74e71ac2 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_10.ts @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 5.0 manages to make all enums into union enums by creating a unique type for each computed member. + module: ES2022 + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +enum binary { + A = 1011 + 'abc', + B = 110 + 'bcd', + C = 101 + 'cde' +} + +type myBinary = binary.A | binary.B; + +function isMyBinary(c: binary): c is myBinary { + return (c === binary.A || c === binary.B); +} + +Assert.isTrue(isMyBinary(binary.B)); +Assert.isFalse(isMyBinary(binary.C)); diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_2.ts b/tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_2.ts new file mode 100644 index 0000000000..04d05952f2 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_2.ts @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 5.0 manages to make all enums into union enums by creating a unique type for each computed member. + module: ES2022 + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +const enum Values { + First = 'aaaaa', + Second = 'bbbbbbbbb', + Third = 'ccccccccc' +} + +type PrimaryValues = Values.First | Values.Second; + +function isPrimaryValues(c: Values): c is PrimaryValues { + return c === Values.First || c === Values.Second; +} + +const firstValue = isPrimaryValues(Values.First); +Assert.isTrue(firstValue); + +const secondValue = isPrimaryValues(Values.Third); +Assert.isFalse(secondValue); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_3.ts b/tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_3.ts new file mode 100644 index 0000000000..3423ca0c4b --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_3.ts @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 5.0 manages to make all enums into union enums by creating a unique type for each computed member. + module: ES2022 + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +const enum Values { + a = 3 / 2, + b = 5 + 1, + c = 1 * 3 +} + +type PrimaryValues = Values.a | Values.b; + +function isPrimaryValues(c: Values): c is PrimaryValues { + return c === Values.a || c === Values.b; +} + +const firstValue = isPrimaryValues(Values.a); +Assert.isTrue(firstValue); + +const secondValue = isPrimaryValues(Values.c); +Assert.isFalse(secondValue); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_4.ts b/tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_4.ts new file mode 100644 index 0000000000..ca24253e1d --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_4.ts @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 5.0 manages to make all enums into union enums by creating a unique type for each computed member. + module: ES2022 + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +enum Color { + Red, + Orange, + Yellow, + Green, + Blue, + Violet +} + +enum Values { + First = 'aaaaa', + Second = 'bbbbbbbbb', + Third = 'ccccccccc' +} + +type PrimaryValues = Color.Red | Values.First; + +function isPrimaryValues(c: Values | Color): c is PrimaryValues { + return c === Color.Red || c === Values.First; +} + +const firstValue = isPrimaryValues(Values.First); +Assert.isTrue(firstValue); + +const secondValue = isPrimaryValues(Color.Red); +Assert.isTrue(secondValue); + +const thirdValue = isPrimaryValues(Color.Yellow); +Assert.isFalse(thirdValue); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_5.ts b/tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_5.ts new file mode 100644 index 0000000000..716d3fdd47 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_5.ts @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 5.0 manages to make all enums into union enums by creating a unique type for each computed member. + module: ES2022 + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +enum E { + A = 10 * 10, // Numeric literal enum member + B = 'foo', // String literal enum member + C = Math.random() // Opaque computed enum member +} + +function getStringValue(e: E): string { + return String(e); +} + +Assert.equal(getStringValue(E.A), 100); +Assert.equal(getStringValue(E.B), 'foo'); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_6.ts b/tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_6.ts new file mode 100644 index 0000000000..4e7a3cdacc --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_6.ts @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 5.0 manages to make all enums into union enums by creating a unique type for each computed member. + module: ES2022 + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +enum ShapeKind { + Circle, + Square, + Star +} + +interface Circle { + kind: ShapeKind.Circle; + radius: number; +} + +interface Square { + kind: ShapeKind.Square; + sideLength: number; +} + +interface Star { + kind: ShapeKind.Star; + sideLength: number; +} + +type values = ShapeKind.Circle | ShapeKind.Square; +function getStringValue(c: ShapeKind): c is values { + return c === ShapeKind.Circle || c === ShapeKind.Square; +} + +Assert.isTrue(getStringValue(ShapeKind.Circle)); +Assert.isTrue(getStringValue(ShapeKind.Square)); +Assert.isFalse(getStringValue(ShapeKind.Star)); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_7.ts b/tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_7.ts new file mode 100644 index 0000000000..1d3fa66a12 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_7.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 5.0 manages to make all enums into union enums by creating a unique type for each computed member. + module: ES2022 + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +enum AnimalFlags { + None = 0, + HasClaws = 1 << 0, + CanFly = 1 << 1, + EatsFish = 1 << 2, + Endangered = 1 << 3, + EndangeredFlyingClawedFishEating = HasClaws | CanFly | EatsFish | Endangered +} + +Assert.equal(AnimalFlags.EndangeredFlyingClawedFishEating, 15); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_8.ts b/tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_8.ts new file mode 100644 index 0000000000..d325603307 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_8.ts @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 5.0 manages to make all enums into union enums by creating a unique type for each computed member. + module: ES2022 + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +const enum Foo { Value = 0x01 } +const enum Bar { Value = 0x02 } +const enum Baz { Value = Foo.Value | Bar.Value } + +Assert.equal(Baz.Value, 3); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_9.ts b/tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_9.ts new file mode 100644 index 0000000000..382c8fff41 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/all_enums_are_union_enums/all_enums_are_union_enums_9.ts @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 5.0 manages to make all enums into union enums by creating a unique type for each computed member. + module: ES2022 + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +const prefix = '/demo'; + +enum Routes { + src = `${prefix}/src`, // "/demo/src" + tsdemo = `${prefix}/tsdemo`, // "/demo/tsdemo" + dist = `${prefix}/dist` // "/demo/dist" +} + +type value = Routes.src | Routes.tsdemo; + +function isRoutes(c: Routes): c is value { + return (c === Routes.src || c === Routes.tsdemo); +} + +Assert.isTrue(isRoutes(Routes.src)); +Assert.isFalse(isRoutes(Routes.dist)); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_1.ts b/tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_1.ts new file mode 100644 index 0000000000..796b2689a7 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_1.ts @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + In TypeScript 5.0, you can now add a const modifier to a type parameter declaration to cause const-like + inference to be the default. + module: ESNext + isCurrent: true + error: { code: Cannot assign to '0' because it is a read-only property } + ---*/ + + +function value(arg: T): T { + return arg; +} + +const myNames = value(['Jack', 'Bob', 'Eve']); +myNames[0] = '1';// Cannot assign to '0' because it is a read-only property \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_10.ts b/tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_10.ts new file mode 100644 index 0000000000..ef57073e6f --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_10.ts @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + In TypeScript 5.0, you can now add a const modifier to a type parameter + declaration to cause const-like inference to be the default. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +function constObjectTest(args: T): T { + return args; +}; +const myObject = { key: 1, value: 'abc' }; + +let myObj = constObjectTest(myObject); +Assert.equal(myObj.key, 1); +Assert.equal(myObj.value, 'abc'); + + +myObj.key = 2; +Assert.equal(myObj.key, 2); +Assert.equal(myObj.value, 'abc'); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_2.ts b/tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_2.ts new file mode 100644 index 0000000000..f65d85e677 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_2.ts @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + In TypeScript 5.0, you can now add a const modifier to a type parameter declaration to cause + const-like inference to be the default. + module: ESNext + isCurrent: true + error: { code: Cannot assign to '0' because it is a read-only property. } + ---*/ + + +function getValue(arg: T): T { + return arg; +} + +const result = getValue({ name: 'Jack', frd: ['Bob', 'Eve'] }); +result.frd[0] = 'Sophia'; // Cannot assign to '0' because it is a read-only property \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_3.ts b/tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_3.ts new file mode 100644 index 0000000000..a59a4af6e6 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_3.ts @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + In TypeScript 5.0, you can now add a const modifier to a type parameter declaration to + cause const-like inference to be the default. + module: ESNext + isCurrent: true + error: { code: Cannot assign to '0' because it is a read-only property. } + ---*/ + + +function getConstValue(arg: T): T { + return arg; +} + +let val = getConstValue(['a' + 'b', 'cc']); +val[0] = 'c'; // Cannot assign to '0' because it is a read-only property \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_4.ts b/tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_4.ts new file mode 100644 index 0000000000..2399f69f54 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_4.ts @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + In TypeScript 5.0, you can now add a const modifier to a type parameter declaration to + cause const-like inference to be the default. + module: ESNext + isCurrent: true + error: { code: Cannot assign to '0' because it is a read-only property. } + ---*/ + + +function getFruit(arg: T): T { + return arg; +} + +const myFruit = getFruit({ shop: 'Jack`s' + ' shop', fruit: ['apple', 'orange'] }); +myFruit.fruit[0] = 'Sophia'; // Cannot assign to '0' because it is a read-only property \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_5.ts b/tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_5.ts new file mode 100644 index 0000000000..76685e3628 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_5.ts @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + In TypeScript 5.0, you can now add a const modifier to a type parameter declaration to + cause const-like inference to be the default. + module: ESNext + isCurrent: true + error: { code: Cannot assign to '0' because it is a read-only property. } + ---*/ + + +type HasNames = { names: readonly string[] }; +function getNamesExactly(arg: T): T['names'] { + return arg.names; +} + +let names = getNamesExactly({ names: ['Alice', 'Bob', 'Eve'] }); +names[0] = 'jack'; // Cannot assign to '0' because it is a read-only property \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_6.ts b/tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_6.ts new file mode 100644 index 0000000000..d012d200b9 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_6.ts @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + In TypeScript 5.0, you can now add a const modifier to a type parameter declaration to + cause const-like inference to be the default. + module: ESNext + isCurrent: true + error: { code: Cannot assign to 'x' because it is a read-only property. } + ---*/ + + +function getNamesObject(arg: T): T { + return arg; +} + +let objectNames = getNamesObject({ x: 1, y: 1 }); +objectNames.x = 2; // Cannot assign to 'x' because it is a read-only property \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_7.ts b/tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_7.ts new file mode 100644 index 0000000000..011cd07240 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_7.ts @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + In TypeScript 5.0, you can now add a const modifier to a type parameter declaration to + cause const-like inference to be the default. + module: ESNext + isCurrent: true + error: { code: Cannot assign to '0' because it is a read-only property. } + ---*/ + + +function getNames(arg: T): T { + return arg; +} + +let newNames = getNames(['a' + 'b', 'cc']); +newNames[0] = 'jack'; // Cannot assign to '0' because it is a read-only property \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_8.ts b/tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_8.ts new file mode 100644 index 0000000000..79e4d6244c --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_8.ts @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + In TypeScript 5.0, you can now add a const modifier to a type parameter + declaration to cause const-like inference to be the default. + module: ESNext + isCurrent: true + error: { code: Cannot assign to '0' because it is a read-only property. } + ---*/ + + +function fruit(arg: T): T { + return arg; +} + +const getMyFruit = fruit({ shop: 'Jack`s' + ' shop', fruit: ['apple', 'orange'] }); +getMyFruit.fruit[0] = 'Sophia'; // Cannot assign to '0' because it is a read-only property \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_9.ts b/tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_9.ts new file mode 100644 index 0000000000..f92c6761db --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/const_type_parameters/const_type_parameters_9.ts @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + In TypeScript 5.0, you can now add a const modifier to a type + parameter declaration to cause const-like inference to be the default. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +function constTest(args: T): T { + return args; +}; + +const myString = ['a', 'b', 'c']; + +let myArr = constTest(myString); +Assert.equal(myArr[2], 'c'); + +myArr[2] = 'd'; +Assert.equal(myArr[2], 'd'); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_1.ts b/tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_1.ts new file mode 100644 index 0000000000..485a836636 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_1.ts @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + Class Decorator: + module: ES2022 + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +function Greeter(value: Function, context: { kind: string }) { + if (context.kind === 'class') { + value.prototype.greet = function () { + return 'hello'; + }; + } +} + +@Greeter +class User { + greet(){ + return 'hi'; + } +} + +let u = new User(); +Assert.equal(u.greet(), 'hello'); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_10.ts b/tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_10.ts new file mode 100644 index 0000000000..140ab2f728 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_10.ts @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + Class Decorator:making classes function-callable + module: ES2022 + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +function logged(value: any, context: { kind: string }) { + if (context.kind === 'field') { + return function (initialValue: number) { + return initialValue = 2; + }; + } +} + +class C { + @logged x = 1; +} + +Assert.equal(new C().x, 2); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_2.ts b/tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_2.ts new file mode 100644 index 0000000000..4bb198b566 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_2.ts @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + Method Decorator:tracing method invocations + module: ES2022 + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +function replaceMethod(value: Function, context: { kind: string }) { + if (context.kind === 'method') { + return function () { + return 'How are you?'; + } + } +} + +class Person { + name: string; + constructor(name: string) { + this.name = name; + } + + @replaceMethod + hello() { + return `Hi ${this.name}!`; + } +} + +const robin = new Person('Robin'); +Assert.equal(robin.hello(), 'How are you?'); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_3.ts b/tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_3.ts new file mode 100644 index 0000000000..e387455e16 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_3.ts @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + Method Decorator:binding methods to instances + module: ES2022 + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +function bind(value: Function, context: { kind: string, name: string, addInitializer(initializer: () => void): void }) { + if (context.kind === 'method') { + context.addInitializer(function (this: any) { + this[context.name] = value.bind(this); + }); + } +} + +class Color { + name: string; + + constructor(myName: string) { + this.name = myName; + } + + @bind + toString() { + return this.name; + } +} + +const green = new Color('green').toString; +Assert.equal(green(), 'green'); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_4.ts b/tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_4.ts new file mode 100644 index 0000000000..9c0ec0dd27 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_4.ts @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + Method Decorator:tracing method invocations + module: ES2022 + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +function trace(value: Function, context: { kind: string }) { + if (context.kind === 'method') { + return function (this: any, ...args: any[]) { + const result = value.apply(this, args) + '!!!'; + return result; + }; + } +} + +class StringBuilder { + str = ''; + + @trace + add(newStr: string) { + this.str += newStr; + } + + @trace + toString() { + return this.str; + } +} + +const sb = new StringBuilder(); +sb.add('Home'); +sb.add('page'); + +Assert.equal(sb.toString(), 'Homepage!!!'); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_5.ts b/tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_5.ts new file mode 100644 index 0000000000..bab1c2d816 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_5.ts @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + Method Decorator:Class getter decorators + module: ES2022 + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +function lazy(value: Function, context: { kind: string, name: string }) { + if (context.kind === 'getter') { + return function (this: object) { + const result = value.call(this); + Object.defineProperty( + this, context.name, + { + value: result, + writable: false + } + ); + return 'This is result.'; + }; + } +} + +class C { + @lazy + get value() { + return 'Result of computation'; + } +} + +const inst = new C(); +Assert.equal(inst.value, 'This is result.'); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_6.ts b/tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_6.ts new file mode 100644 index 0000000000..02077f22d3 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_6.ts @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + Method Decorator:Class setter decorators + module: ES2022 + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +function logged(value: Function, context: { kind: string }) { + if (context.kind === 'setter') { + return function (this: any, ...args: any[]) { + const ret = value.call(this, ...args); + return ret; + }; + } +} + +class A { + public value: number = 0; + + @logged + set x(newValue) { + this.value = newValue; + } + + get x() { + return this.value; + } +} + +const X = new A(); +X.x = 1; +Assert.equal(X.value, 1); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_7.ts b/tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_7.ts new file mode 100644 index 0000000000..d853978176 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_7.ts @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + Property Decorator(field):changing initialization values of fields + module: ES2022 + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +function twice(value: undefined, context: { kind: string }) { + if (context.kind === 'field') { + return (initialValue: number) => initialValue * 2; + } +} + +class test { + @twice + x = 2; +} + +let p = new test(); +Assert.equal(p.x, 4); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_8.ts b/tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_8.ts new file mode 100644 index 0000000000..1b1ba0fb50 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_8.ts @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + Property Decorator(field):static public fields(It cannot change or replace its field) + module: ES2022 + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +function enumEntry(value: undefined, context: { kind: string, name: string }) { + if (context.kind === 'field') { + console.log(`starting ${context.name}`); + } +} + +class colorClass { + @enumEntry + static red = 'red'; +} + +Assert.equal(colorClass.red, 'red'); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_9.ts b/tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_9.ts new file mode 100644 index 0000000000..b623475c7d --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/decorators/decorators_9.ts @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + Accessor Decorator + module: ES2022 + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +function accessorDecorator(value: any, { kind }: { kind: string }) { + if (kind === 'accessor') { + let { get, set } = value; + + return { + get() { + return get.call(this); + }, + + set(val: number) { + Assert.equal(val, 123); + return set.call(this, val); + }, + + init(initialValue: number) { + Assert.equal(initialValue, 1); + return initialValue; + } + }; + } +} + +class accessorTest { + @accessorDecorator + accessor x = 1; +} + +let d = new accessorTest(); +d.x; +d.x = 123; \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_1.ts b/tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_1.ts new file mode 100644 index 0000000000..8c2e2cf62c --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_1.ts @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + In TypeScript 5.0, Check implicit type conversion of relational operator > < <= >=, prompt type error. + module: ESNext + isCurrent: true + error: { code: Operator '>' cannot be applied to types 'string | number' and 'number' } + ---*/ + + +function func(ns: number | string) { + return ns > 4; // Operator '>' cannot be applied to types 'string | number' and 'number' +} \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_10.ts b/tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_10.ts new file mode 100644 index 0000000000..a3c6088507 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_10.ts @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + In TypeScript 5.0, Check implicit type conversion of relational operator > < <= >=, prompt type error. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +function funcK(ns: number | string) { + return -ns < 4; +} + +Assert.equal(funcK(2), true); +Assert.equal(funcK(-6), false); +Assert.equal(funcK('abc'), false); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_2.ts b/tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_2.ts new file mode 100644 index 0000000000..d37429bf55 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_2.ts @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + In TypeScript 5.0, Check implicit type conversion of relational operator > < <= >=, prompt type error. + module: ESNext + isCurrent: true + error: { code: Operator '<' cannot be applied to types 'string | number' and 'number' } + ---*/ + + +function funcA(ns: number | string) { + return ns < 4; // Operator '<' cannot be applied to types 'string | number' and 'number' +} \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_3.ts b/tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_3.ts new file mode 100644 index 0000000000..ae94a66543 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_3.ts @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + In TypeScript 5.0, Check implicit type conversion of relational operator > < <= >=, prompt type error. + module: ESNext + isCurrent: true + error: { code: Operator '<=' cannot be applied to types 'string | number' and 'number' } + ---*/ + + +function funcB(ns: number | string) { + return ns <= 4; // Operator '<=' cannot be applied to types 'string | number' and 'number' +} \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_4.ts b/tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_4.ts new file mode 100644 index 0000000000..3de8cdbe0f --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_4.ts @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + In TypeScript 5.0, Check implicit type conversion of relational operator > < <= >=, prompt type error. + module: ESNext + isCurrent: true + error: { code: Operator '>=' cannot be applied to types 'string | number' and 'number' } + ---*/ + + +function funcC(ns: number | string) { + return ns >= 4; // Operator '>=' cannot be applied to types 'string | number' and 'number' +} \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_5.ts b/tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_5.ts new file mode 100644 index 0000000000..373cc35a4c --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_5.ts @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + In TypeScript 5.0, Check implicit type conversion of relational operator > < <= >=, prompt type error. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +function funcD(ns: number | string) { + return +ns > 4; +} + +Assert.equal(funcD(2), false); +Assert.equal(funcD(8), true); +Assert.equal(funcD('abc'), false); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_6.ts b/tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_6.ts new file mode 100644 index 0000000000..c537bdcb44 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_6.ts @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + In TypeScript 5.0, Check implicit type conversion of relational operator > < <= >=, prompt type error. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +function funcE(ns: number | string) { + return +ns < 4; +} + +Assert.equal(funcE(5), false); +Assert.equal(funcE(3), true); +Assert.equal(funcE('abc'), false); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_7.ts b/tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_7.ts new file mode 100644 index 0000000000..2361ab6408 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_7.ts @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + In TypeScript 5.0, Check implicit type conversion of relational operator > < <= >=, prompt type error. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +function funcF(ns: number | string) { + return +ns <= 4; +} + +Assert.equal(funcF(5), false); +Assert.equal(funcF(4), true); +Assert.equal(funcF('abc'), false); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_8.ts b/tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_8.ts new file mode 100644 index 0000000000..6f12a06add --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_8.ts @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + In TypeScript 5.0, Check implicit type conversion of relational operator > < <= >=, prompt type error. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +function funcG(ns: number | string) { + return +ns >= 4; +} + +Assert.equal(funcG(2), false); +Assert.equal(funcG(4), true); +Assert.equal(funcG('abc'), false); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_9.ts b/tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_9.ts new file mode 100644 index 0000000000..e09b2105cd --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/forbidden_implicit_coercions_in_relational_operators/forbidden_implicit_coercions_in_relational_operators_9.ts @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + In TypeScript 5.0, Check implicit type conversion of relational operator > < <= >=, prompt type error. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +function funcH(ns: number | string) { + return -ns > 4; +} + +Assert.equal(funcH(2), false); +Assert.equal(funcH(-6), true); +Assert.equal(funcH('abc'), false); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_1.ts b/tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_1.ts new file mode 100644 index 0000000000..f97f9a22c8 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_1.ts @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 5.0 now allows JSDoc to declare overloads with a new @overload tag. + Each JSDoc comment with an @overload tag is treated as a distinct overload for the following function declaration. + module: ES2022 + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +/** + * @overload + * @param {string} a + * @param {string} b + * @return {string} + */ + +/** + * @overload + * @param {number} a + * @param {number} b + * @return {number} + */ + +function add(a: number | string, b: number | string) { + if (typeof a === 'number' && typeof b === 'number') { + return a + b; + } else if (typeof a === 'string' && typeof b === 'string') { + return a.concat(b); + } else { + return 0; + } +} + +Assert.equal(add(1, 2), 3); +Assert.equal(add('hello', 'world'), 'helloworld'); +Assert.equal(add('hello', 1), 0); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_10.ts b/tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_10.ts new file mode 100644 index 0000000000..f2023883ab --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_10.ts @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 5.0 now allows JSDoc to declare overloads with a new @overload tag. + Each JSDoc comment with an @overload tag is treated as a distinct overload for the following function declaration. + module: ES2022 + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +/** + * @overload + * @param {string} a + * @param {string} b + * @return {string} + */ + +/** + * @overload + * @param {number} a + * @param {number} b + * @return {number} + */ + +class printValue { + overload(a: string | number, b: string | number) { + if (typeof a === 'number' && typeof b === 'number') { + return a + b; + } else if (typeof a === 'string' && typeof b === 'string') { + return a.concat(b); + } + } +} + +let ol = new printValue(); +Assert.isUndefined(ol.overload('hello', 1)); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_2.ts b/tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_2.ts new file mode 100644 index 0000000000..f04ef431fd --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_2.ts @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 5.0 now allows JSDoc to declare overloads with a new @overload tag. + Each JSDoc comment with an @overload tag is treated as a distinct overload for the following function declaration. + module: ES2022 + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +/** + * @overload + * @param {string} a + * @return {string} + */ + +/** + * @overload + * @param {string} a + * @param {string} b + */ + +function printValue(a: string, b?: string) { + if (b) { + return a.concat(b); + } + else { + return a.toUpperCase(); + } +} +Assert.equal(printValue('hello'), 'HELLO'); +Assert.equal(printValue('hello', 'world'), 'helloworld'); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_3.ts b/tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_3.ts new file mode 100644 index 0000000000..6056c208b5 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_3.ts @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 5.0 now allows JSDoc to declare overloads with a new @overload tag. + Each JSDoc comment with an @overload tag is treated as a distinct overload for the following function declaration. + module: ES2022 + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +/** + * @overload + * @param {string} a + * @return {string} + */ + +/** + * @overload + * @param {number} a + * @param {number} b + * @return {number} + */ + +function printValue(a: string | number, b?: number) { + if (typeof a === 'number' && typeof b === 'number') { + return a + b; + } + else { + return a; + } +} + +Assert.equal(printValue(1, 2), 3); +Assert.equal(printValue('hello'), 'hello'); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_4.ts b/tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_4.ts new file mode 100644 index 0000000000..b989f88b01 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_4.ts @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 5.0 now allows JSDoc to declare overloads with a new @overload tag. + Each JSDoc comment with an @overload tag is treated as a distinct overload for the following function declaration. + module: ES2022 + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +/** + * @overload + * @param {string} a + * @return {string} + */ + +/** + * @overload + * @param {number} a + * @param {number} b + * @return {number} + */ + +class printValue { + overload(a: string | number, b?: number) { + if (typeof a === 'number' && typeof b === 'number') { + return a + b; + } + else { + return a; + } + } +} + +let ol = new printValue(); +Assert.equal(ol.overload(1, 2), 3); +Assert.equal(ol.overload('hello'), 'hello'); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_5.ts b/tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_5.ts new file mode 100644 index 0000000000..ad75c9b9cc --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_5.ts @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 5.0 now allows JSDoc to declare overloads with a new @overload tag. + Each JSDoc comment with an @overload tag is treated as a distinct overload for the following function declaration. + module: ES2022 + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +/** + * @overload + * @param {string} a + * @param {string} b + * @return {string} + */ + +/** + * @overload + * @param {number} a + * @param {number} b + * @return {number} + */ + +class printValue { + overload(a: string | number, b: string | number) { + if (typeof a === 'number' && typeof b === 'number') { + return a + b; + } else if (typeof a === 'string' && typeof b === 'string') { + return a.concat(b); + } + } +} + +let ol = new printValue(); +Assert.equal(ol.overload(1, 2), 3); +Assert.equal(ol.overload('hello', 'world'), 'helloworld'); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_6.ts b/tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_6.ts new file mode 100644 index 0000000000..47f4c5c5a0 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_6.ts @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 5.0 now allows JSDoc to declare overloads with a new @overload tag. + Each JSDoc comment with an @overload tag is treated as a distinct overload for the following function declaration. + module: ES2022 + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +/** + * @overload + * @param {string} a + * @return {string} + */ + +/** + * @overload + * @param {string} a + * @param {string} b + * @return {string} + */ + +class printValue { + overload(a: string, b?: string) { + if (b) { + return a.concat(b); + } + else { + return a.toUpperCase(); + } + } +} + +let ol = new printValue(); +Assert.equal(ol.overload('hello'), 'HELLO'); +Assert.equal(ol.overload('hello', 'world'), 'helloworld'); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_7.ts b/tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_7.ts new file mode 100644 index 0000000000..8d315222ab --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_7.ts @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 5.0 now allows JSDoc to declare overloads with a new @overload tag. + Each JSDoc comment with an @overload tag is treated as a distinct overload for the following function declaration. + module: ES2022 + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +/** + * @overload + * @param {void} obj + */ + +/** + * @overload + * @param {Shape} obj + */ + +interface Shape { + x: number; + y: number; + height: number; + width: number; +} + +class Square { + public x: number; + public y: number; + public height: number; + public width: number; + + constructor(obj?: Shape) { + this.x = obj?.x ?? 0; + this.y = obj?.y ?? 0; + this.height = obj?.height ?? 0; + this.width = obj?.width ?? 0; + } +} + +let square: Square; +square = new Square(); +square.x = 10; +square.y = 50; +square.height = 100; +square.width = 100; + +Assert.equal(square.x, 10); +Assert.equal(square.y, 50); +Assert.equal(square.height, 100); +Assert.equal(square.width, 100); + +let squareConfig: Shape; +squareConfig = { x: 10, y: 50, height: 100, width: 100 }; + +let squareNew: Square; +squareNew = new Square(squareConfig); + +Assert.equal(squareNew.x, 10); +Assert.equal(squareNew.y, 50); +Assert.equal(squareNew.height, 100); +Assert.equal(squareNew.width, 100); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_8.ts b/tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_8.ts new file mode 100644 index 0000000000..54b7659bc5 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_8.ts @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 5.0 now allows JSDoc to declare overloads with a new @overload tag. + Each JSDoc comment with an @overload tag is treated as a distinct overload for the following function declaration. + module: ES2022 + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +/** + * @overload + * @param {void} obj + */ + +/** + * @overload + * @param {any} obj + */ + +class Square { + public x: number; + public y: number; + public height: number; + public width: number; + + constructor(obj?: any) { + this.x = obj?.x ?? 0; + this.y = obj?.y ?? 0; + this.height = obj?.height ?? 0; + this.width = obj?.width ?? 0; + } +} + +let squareConfig: Square; +squareConfig = new Square(); +squareConfig.x = 10; +squareConfig.y = 50; +squareConfig.height = 100; +squareConfig.width = 100; + +Assert.equal(squareConfig.x, 10); +Assert.equal(squareConfig.y, 50); +Assert.equal(squareConfig.height, 100); +Assert.equal(squareConfig.width, 100); + +let square: Square; +square = new Square({ x: 10, y: 50, height: 100, width: 100 }); + +Assert.equal(square.x, 10); +Assert.equal(square.y, 50); +Assert.equal(square.height, 100); +Assert.equal(square.width, 100); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_9.ts b/tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_9.ts new file mode 100644 index 0000000000..6bedfa520c --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/overload_support_in_jsdoc/overload_support_in_jsdoc_9.ts @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 5.0 now allows JSDoc to declare overloads with a new @overload tag. + Each JSDoc comment with an @overload tag is treated as a distinct overload for the following function declaration. + module: ES2022 + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +/** + * @overload + * @param {Shape} obj + */ + +/** + * @overload + * @param {any} obj + */ + +interface Shape { + x: number; + y: number; + height: number; + width: number; +} + +class Square { + public x: number; + public y: number; + public height: number; + public width: number; + + constructor(obj: Shape) { + this.x = obj?.x ?? 0; + this.y = obj?.y ?? 0; + this.height = obj?.height ?? 0; + this.width = obj?.width ?? 0; + } +} + +let squareConfig: Shape; +squareConfig = { x: 10, y: 50, height: 100, width: 100 }; + +let square: Square; +square = new Square(squareConfig); + +Assert.equal(square.x, 10); +Assert.equal(square.y, 50); +Assert.equal(square.height, 100); +Assert.equal(square.width, 100); + +let square_any: Square; +square_any = new Square({ x: 10, y: 50, height: 100, width: 100 }); + +Assert.equal(square_any.x, 10); +Assert.equal(square_any.y, 50); +Assert.equal(square_any.height, 100); +Assert.equal(square_any.width, 100); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_1.ts b/tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_1.ts new file mode 100644 index 0000000000..f8c61848cd --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_1.ts @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + satisfies can catch type mismatches. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +// @ts-check +/** + * @typedef {Function} Greeter + * @param {string} name + * @return {string} + */ + +interface Greeter { + greet(name: string): string; +} + +/** +* @satisfies {Greeter} +*/ +function greeter(name: string) { + return ('Hello ' + name); +} + +const myGreeter = greeter('Jack'); +Assert.equal(myGreeter, 'Hello Jack'); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_10.ts b/tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_10.ts new file mode 100644 index 0000000000..1763dccdec --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_10.ts @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + satisfies can catch type mismatches. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +// @ts-check +/** +* @typedef { 'circle' | 'square' | 'triangle'} Shapes +*/ + +/** +* @satisfies {Record} +*/ +const shapesInGraphic = { + 'circle': 4, + 'square': 'one', + 'triangle': 3 +}; + +Assert.equal(shapesInGraphic.square.toUpperCase(), 'ONE'); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_2.ts b/tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_2.ts new file mode 100644 index 0000000000..b6870176d6 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_2.ts @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + satisfies can catch type mismatches. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +// @ts-check +/** + * @satisfies { 'foo' | 'bar' } + */ +const messageRight = 'foo'; +Assert.equal(messageRight, 'foo'); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_3.ts b/tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_3.ts new file mode 100644 index 0000000000..f25659a6e7 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_3.ts @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + satisfies can catch type mismatches. + module: ESNext + isCurrent: true + ---*/ + +import { Assert } from '../../../suite/assert.js' + +// @ts-check +/** + * @satisfies { 'foo' | 'bar' } + */ +const myMessage = 'bar'; +Assert.equal(myMessage, 'bar'); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_4.ts b/tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_4.ts new file mode 100644 index 0000000000..fab2b07e30 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_4.ts @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + satisfies can catch type mismatches. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +type Colors = 'red' | 'green' | 'blue'; + +type RGB = [red: number, green: number, blue: number]; + +/** + * @satisfies Colors | RGB + */ +const palette = { + red: [255, 0, 0], + green: '#00ff00', + blue: [0, 0, 255] +} + +Assert.equal(palette.green, '#00ff00'); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_5.ts b/tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_5.ts new file mode 100644 index 0000000000..3d55a37135 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_5.ts @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + satisfies can catch type mismatches. + module: ESNext + isCurrent: true + ---*/ + +import { Assert } from '../../../suite/assert.js' + +// @ts-check +/** + * @typedef CompilerOptions + * @prop {boolean} [strict] + * @prop {string} [outDir] + */ + +/** + * @satisfies {CompilerOptions} + */ +let myCompilerOptions = { + strict: true, + outDir: '../lib' +}; + +Assert.equal(myCompilerOptions.strict, true); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_6.ts b/tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_6.ts new file mode 100644 index 0000000000..a7971acc93 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_6.ts @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + satisfies can catch type mismatches. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +// @ts-check +/** + * @typedef CompilerOptions + * @prop {boolean} [strict] + * @prop {string} [outDir] + */ + +/** + * @typedef ConfigSettings + * @prop {CompilerOptions} [compilerOptions] + * @prop {string | string[]} [extends] + */ + +let myConfigSettings = /** @satisfies {ConfigSettings} */ { + compilerOptions: { + strict: true, + outDir: '../lib' + }, + extends: [ + '@tsconfig/strictest/tsconfig.json', + '../../../tsconfig.base.json' + ] +}; + +Assert.isTrue(myConfigSettings.compilerOptions.strict); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_7.ts b/tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_7.ts new file mode 100644 index 0000000000..71d6b8aa4f --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_7.ts @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + satisfies can catch type mismatches. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +// @ts-check +/** + * @typedef { 'hello world' | 'Hello, world' } WelcomeMessage + */ + +/** @satisfies { WelcomeMessage } */ +const message = 'hello world'; +Assert.equal(message, 'hello world'); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_8.ts b/tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_8.ts new file mode 100644 index 0000000000..0e1f0c78a9 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_8.ts @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + satisfies can catch type mismatches. + module: ESNext + isCurrent: true + ---*/ + +import { Assert } from '../../../suite/assert.js' + +// @ts-check +/** + * @typedef { 'hello world' | 'Hello, world' } WelcomeMessage + */ + +/** @satisfies { WelcomeMessage } */ +const myMessage = 'Hello, world'; +Assert.equal(myMessage, 'Hello, world'); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_9.ts b/tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_9.ts new file mode 100644 index 0000000000..8a866b1bfc --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/satisfies_support_in_jsdoc/satisfies_support_in_jsdoc_9.ts @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + satisfies can catch type mismatches. + module: ESNext + isCurrent: true + ---*/ + +import { Assert } from '../../../suite/assert.js' + +// @ts-check +/** + * @typedef { 'red' | 'green' | 'blue' } Colors + * */ + +/** + * @satisfies { Record } + */ +const favoriteColors = { + red: 'yes', + green: false, + blue: 'kinda' +} + +Assert.equal(favoriteColors.red, 'yes'); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/models/factory.ts b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/models/factory.ts new file mode 100644 index 0000000000..9b339b38f1 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/models/factory.ts @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +export class spaceShip { + name = 'Star'; + + setName(myName: string) { + this.name = myName; + } + + getName() { + return this.name; + } +} + +export class shipString { + ship = 'ship'; + + toUpper() { + return this.ship.toUpperCase(); + } +} \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/models/index.ts b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/models/index.ts new file mode 100644 index 0000000000..e63973a70a --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/models/index.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +export type * as fac from './factory.js' +export * from './factory.js' + +export type * as vehicles from './vehicles.js' +export * from './vehicles.js' \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/models/vehicles.ts b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/models/vehicles.ts new file mode 100644 index 0000000000..4f59b3232f --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/models/vehicles.ts @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +export class vehiclesFactory { + name = 'Audi'; + + setName(myName: string) { + this.name = myName; + } + + getName() { + return this.name; + } +} + +export class myVehicles { + myCar = 'alto'; + + toUpper() { + return this.myCar.toUpperCase(); + } +} \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/shap/circle.ts b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/shap/circle.ts new file mode 100644 index 0000000000..ce03ebaed3 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/shap/circle.ts @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +export class circleArea { + radius = 2; + PI = 3; + + getArea() { + return this.PI * this.radius * this.radius; + } +} \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/shap/index.ts b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/shap/index.ts new file mode 100644 index 0000000000..ed432e38e3 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/shap/index.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +export type * as circle from './circle.js' +export * from './circle.js' + +export type * as square from './square.js' +export * from './square.js' \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/shap/square.ts b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/shap/square.ts new file mode 100644 index 0000000000..029581bc2d --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/shap/square.ts @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +export class squareArea { + length = 3; + + getArea(){ + return this.length * this.length; + } +} \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_1.ts b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_1.ts new file mode 100644 index 0000000000..22a6832aa7 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_1.ts @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 5.0 support for export * as ns from "module" re-exports. + module: es2020 + moduleResolution: nodenext + target: es2021 + isCurrent: true + ---*/ + + +import { fac, spaceShip } from './models/index.js' +import { Assert } from '../../../suite/assert.js' + +function takeASpaceship(s: fac.spaceShip) { + Assert.equal(s.getName(), 'Star'); +} + +const mySpaceship = new spaceShip(); +takeASpaceship(mySpaceship); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_10.ts b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_10.ts new file mode 100644 index 0000000000..31fb63b5a8 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_10.ts @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 5.0 support for export * from "module" re-exports. + module: ES2022 + isCurrent: true + ---*/ + + +import { spaceShip } from './models/index.js' +import { circleArea } from './shap/index.js' +import { Assert } from '../../../suite/assert.js' + +const mySpaceShip = new spaceShip(); +const myCirlceArea = new circleArea(); + +Assert.equal(mySpaceShip.getName(), 'Star'); +Assert.equal(myCirlceArea.getArea(), 12); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_11.ts b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_11.ts new file mode 100644 index 0000000000..ae4b7d0e7a --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_11.ts @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 5.0 support for export * from "module" or export * as ns from "module" re-exports. + module: ES2022 + isCurrent: true + ---*/ + + +import { fac, spaceShip, vehicles, vehiclesFactory } from './models/index.js' +import { circle, circleArea, square, squareArea } from './shap/index.js' +import { Assert } from '../../../suite/assert.js' + +function takeASpaceship(s: fac.spaceShip) { + Assert.equal(s.getName(), 'Star'); +} + +function takeVehicles(s: vehicles.vehiclesFactory) { + Assert.equal(s.getName(), 'Audi'); +} + +function takeCircleArea(s: circle.circleArea) { + Assert.equal(s.getArea(), 12); +} + +function takeSquareArea(s: square.squareArea) { + Assert.equal(s.getArea(), 9); +} + +const mySpaceship = new spaceShip(); +const myVehicles = new vehiclesFactory(); + +takeASpaceship(mySpaceship); +takeVehicles(myVehicles); + +const myCirlceArea = new circleArea(); +const mySquareArea = new squareArea(); + +takeCircleArea(myCirlceArea); +takeSquareArea(mySquareArea); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_12.ts b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_12.ts new file mode 100644 index 0000000000..2b2a460093 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_12.ts @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 5.0 support for export * from "module" or export * as ns from "module" re-exports. + module: ES2022 + isCurrent: true + ---*/ + + +import { spaceShip, vehiclesFactory } from './models/index.js' +import { circleArea, squareArea } from './shap/index.js' +import { Assert } from '../../../suite/assert.js' + +const mySpaceship = new spaceShip(); +const myVehicles = new vehiclesFactory(); + +Assert.equal(mySpaceship.getName(), 'Star'); +Assert.equal(myVehicles.getName(), 'Audi'); + +myVehicles.setName('car'); +Assert.equal(myVehicles.getName(), 'car'); + +const myCirlce = new circleArea(); +const mySqueare = new squareArea(); + +Assert.equal(myCirlce.getArea(), 12); +Assert.equal(mySqueare.getArea(), 9); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_2.ts b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_2.ts new file mode 100644 index 0000000000..777c88b064 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_2.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 5.0 support for export * from "module" re-exports. + module: ES2022 + isCurrent: true + ---*/ + + +import { spaceShip } from './models/index.js' +import { Assert } from '../../../suite/assert.js' + +const mySpaceShip = new spaceShip(); +Assert.equal(mySpaceShip.getName(), 'Star'); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_3.ts b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_3.ts new file mode 100644 index 0000000000..9597148a49 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_3.ts @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 5.0 support for export * from "module" or export * as ns from "module" re-exports. + module: ES2022 + isCurrent: true + ---*/ + + +import { fac, spaceShip, vehicles, vehiclesFactory } from './models/index.js' +import { Assert } from '../../../suite/assert.js' + +function takeASpaceship(s: fac.spaceShip) { + Assert.equal(s.getName(), 'Star'); +} + +function takeVehicles(s: vehicles.vehiclesFactory) { + Assert.equal(s.getName(), 'Audi'); +} + +const mySpaceship = new spaceShip(); +const myVehicles = new vehiclesFactory(); + +takeASpaceship(mySpaceship); +takeVehicles(myVehicles); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_4.ts b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_4.ts new file mode 100644 index 0000000000..d61b74e6d2 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_4.ts @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 5.0 support for export * from "module" or export * as ns from "module" re-exports. + module: ES2022 + isCurrent: true + ---*/ + + +import { spaceShip, vehiclesFactory } from './models/index.js' +import { Assert } from '../../../suite/assert.js' + +const mySpaceship = new spaceShip(); +const myVehicles = new vehiclesFactory(); + +Assert.equal(mySpaceship.getName(), 'Star'); +Assert.equal(myVehicles.getName(), 'Audi'); + +myVehicles.setName('car'); +Assert.equal(myVehicles.getName(), 'car'); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_5.ts b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_5.ts new file mode 100644 index 0000000000..fd2e3c0bfa --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_5.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 5.0 support for export * as ns from "module" re-exports. + module: ES2022 + isCurrent: true + ---*/ + + +import { fac, spaceShip, shipString } from './models/index.js' +import { Assert } from '../../../suite/assert.js' + +function takeASpaceship(s: fac.spaceShip, d: fac.shipString) { + Assert.equal(s.getName(), 'Star'); + Assert.equal(d.toUpper(), 'SHIP'); +} + +const mySpaceship = new spaceShip(); +const myShipString = new shipString(); + +takeASpaceship(mySpaceship, myShipString); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_6.ts b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_6.ts new file mode 100644 index 0000000000..072de332ea --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_6.ts @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 5.0 support for export * from "module" re-exports. + module: ES2022 + isCurrent: true + ---*/ + + +import { spaceShip, shipString } from './models/index.js' +import { Assert } from '../../../suite/assert.js' + +const mySpaceship = new spaceShip(); +const myShipString = new shipString(); + +Assert.equal(mySpaceship.getName(), 'Star'); +Assert.equal(myShipString.toUpper(), 'SHIP'); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_7.ts b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_7.ts new file mode 100644 index 0000000000..a1deb5df68 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_7.ts @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 5.0 support for export * as ns from "module" re-exports. + module: ES2022 + isCurrent: true + ---*/ + + +import { fac, spaceShip, shipString, vehicles, vehiclesFactory, myVehicles } from './models/index.js' +import { Assert } from '../../../suite/assert.js' + +function takeASpaceship(s: fac.spaceShip, d: fac.shipString) { + Assert.equal(s.getName(), 'Star'); + Assert.equal(d.toUpper(), 'SHIP'); +} + +function takeVehicles(s: vehicles.vehiclesFactory, d: vehicles.myVehicles) { + Assert.equal(s.getName(), 'Audi'); + Assert.equal(d.myCar, 'alto'); +} + +const mySpaceship = new spaceShip(); +const myShipString = new shipString(); +takeASpaceship(mySpaceship, myShipString); + +const myCar = new vehiclesFactory(); +const myCarToUpper = new myVehicles(); +takeVehicles(myCar, myCarToUpper); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_8.ts b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_8.ts new file mode 100644 index 0000000000..bb4d04614d --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_8.ts @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 5.0 support for export * from "module" re-exports. + module: ES2022 + isCurrent: true + ---*/ + + +import { spaceShip, shipString, vehiclesFactory, myVehicles } from './models/index.js' +import { Assert } from '../../../suite/assert.js' + +const mySpaceship = new spaceShip(); +const myShipString = new shipString(); + +Assert.equal(mySpaceship.getName(), 'Star'); +Assert.equal(myShipString.toUpper(), 'SHIP'); + +const vehicles = new vehiclesFactory(); +const myCar = new myVehicles(); + +Assert.equal(vehicles.getName(), 'Audi'); +Assert.equal(myCar.toUpper(), 'ALTO'); \ No newline at end of file diff --git a/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_9.ts b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_9.ts new file mode 100644 index 0000000000..5ae789d8b0 --- /dev/null +++ b/tests/ts_extra_tests/test_ts_cases/5.0/support_for_export_type/support_for_export_type_9.ts @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 5.0 support for export * as ns from "module" re-exports. + module: ES2022 + isCurrent: true + ---*/ + + +import { fac, spaceShip } from './models/index.js' +import { circle, circleArea } from './shap/index.js' +import { Assert } from '../../../suite/assert.js' + +function takeASpaceship(s: fac.spaceShip) { + Assert.equal(s.getName(), 'Star'); +} + +function getMyCirlceArea(s: circle.circleArea) { + Assert.equal(s.getArea(), 12); +} + +const mySpaceship = new spaceShip(); +const myCirlceArea = new circleArea(); + +takeASpaceship(mySpaceship); +getMyCirlceArea(myCirlceArea); \ No newline at end of file