1/* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16function drawText({ text = '', position: [x, y] = [0, 0] }): void { // NOT OK 17 // Draw text 18} 19drawText({ text: 'Figure 1', position: [10, 20] }); 20 21const hello = ({ // NOT OK 22 firstName, 23 lastName, 24}: { 25 firstName: string; 26 lastName: string; 27}): string => `Hello ${firstName} ${lastName}`; 28console.log(hello({ firstName: 'Karl', lastName: 'Marks' })); 29 30const person = { firstName: 'Adam', lastName: 'Smith' }; 31console.log(hello(person)); 32 33interface I { 34 d: number 35} 36 37function f1({d = 1}: I) { // NOT OK 38} 39f1({d:2}) 40 41function f2({d = 1}: {d: number}) { // NOT OK 42} 43f2({d:2}) 44 45function f3({x, ...y}) { // NOT OK 46 console.log(x); 47 Object.keys(y).forEach(k => console.log(k, y[k])) 48} 49f3({x: 1, b: 2, c: 3}) 50 51function f4([a, b]): void { 52 console.log(a, b); 53} 54f4(['Hello', 'Wolrd']); 55 56function f5([a, b]: number[]): void { 57 console.log(a, b); 58} 59f5([1, 2, 3]); 60 61function f6([a, [b, c]]): void { 62 console.log(a, b, c); 63} 64f6([1, [2, 3]]); 65 66function f7([a, b, ...c]) { // NOT OK 67 console.log(a, b, c); 68} 69f7([1, 2, 3, 4]) 70 71function f8([a, b, [c, ...d]]) { // NOT OK 72 console.log(a, b, c, d); 73} 74f8([1, 2, [3, 4, 5]]) 75 76function f9([a, {b, c}]): void { // NOT OK 77 console.log(a, b, c); 78} 79f9([1, {b: 2, c: 3}]); 80 81function f10([a, [b, {c: d, e: f}]]): void { // NOT OK 82 console.log(a, b, d, f); 83} 84f10([1, [2, {c : 3, e: 4}]]); 85 86function f11([a, b]: Set<number>): void { // NOT OK 87 console.log(a, b); 88} 89f11(new Set([1, 2, 3, 4])); 90