1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
|
//// [renamingDestructuredPropertyInFunctionType.ts]
// GH#37454, GH#41044
type O = { a?: string; b: number; c: number; };
type F1 = (arg: number) => any; // OK
type F2 = ({ a: string }: O) => any; // Error
type F3 = ({ a: string, b, c }: O) => any; // Error
type F4 = ({ a: string }: O) => any; // Error
type F5 = ({ a: string, b, c }: O) => any; // Error
type F6 = ({ a: string }) => typeof string; // OK
type F7 = ({ a: string, b: number }) => typeof number; // Error
type F8 = ({ a, b: number }) => typeof number; // OK
type F9 = ([a, b, c]) => void; // OK
type G1 = new (arg: number) => any; // OK
type G2 = new ({ a: string }: O) => any; // Error
type G3 = new ({ a: string, b, c }: O) => any; // Error
type G4 = new ({ a: string }: O) => any; // Error
type G5 = new ({ a: string, b, c }: O) => any; // Error
type G6 = new ({ a: string }) => typeof string; // OK
type G7 = new ({ a: string, b: number }) => typeof number; // Error
type G8 = new ({ a, b: number }) => typeof number; // OK
type G9 = new ([a, b, c]) => void; // OK
// Below are Error but renaming is retained in declaration emit,
// since elinding it would leave invalid syntax.
type F10 = ({ "a": string }) => void; // Error
type F11 = ({ 2: string }) => void; // Error
type F12 = ({ ["a"]: string }: O) => void; // Error
type F13 = ({ [2]: string }) => void; // Error
type G10 = new ({ "a": string }) => void; // Error
type G11 = new ({ 2: string }) => void; // Error
type G12 = new ({ ["a"]: string }: O) => void; // Error
type G13 = new ({ [2]: string }) => void; // Error
interface I {
method1(arg: number): any; // OK
method2({ a: string }): any; // Error
(arg: number): any; // OK
({ a: string }): any; // Error
new (arg: number): any; // OK
new ({ a: string }): any; // Error
}
// Below are OK but renaming should be removed from declaration emit
function f1({ a: string }: O) { }
const f2 = function({ a: string }: O) { };
const f3 = ({ a: string, b, c }: O) => { };
const f4 = function({ a: string }: O): typeof string { return string; };
const f5 = ({ a: string, b, c }: O): typeof string => '';
const obj1 = {
method({ a: string }: O) { }
};
const obj2 = {
method({ a: string }: O): typeof string { return string; }
};
function f6({ a: string = "" }: O) { }
const f7 = ({ a: string = "", b, c }: O) => { };
const f8 = ({ "a": string }: O) => { };
function f9 ({ 2: string }) { };
function f10 ({ ["a"]: string }: O) { };
const f11 = ({ [2]: string }) => { };
// In below case `string` should be kept because it is used
function f12({ a: string = "" }: O): typeof string { return "a"; }
//// [renamingDestructuredPropertyInFunctionType.js]
// GH#37454, GH#41044
// Below are OK but renaming should be removed from declaration emit
function f1({ a: string }) { }
const f2 = function ({ a: string }) { };
const f3 = ({ a: string, b, c }) => { };
const f4 = function ({ a: string }) { return string; };
const f5 = ({ a: string, b, c }) => '';
const obj1 = {
method({ a: string }) { }
};
const obj2 = {
method({ a: string }) { return string; }
};
function f6({ a: string = "" }) { }
const f7 = ({ a: string = "", b, c }) => { };
const f8 = ({ "a": string }) => { };
function f9({ 2: string }) { }
;
function f10({ ["a"]: string }) { }
;
const f11 = ({ [2]: string }) => { };
// In below case `string` should be kept because it is used
function f12({ a: string = "" }) { return "a"; }
//// [renamingDestructuredPropertyInFunctionType.d.ts]
type O = {
a?: string;
b: number;
c: number;
};
type F1 = (arg: number) => any;
type F2 = ({ a }: O) => any;
type F3 = ({ a, b, c }: O) => any;
type F4 = ({ a }: O) => any;
type F5 = ({ a, b, c }: O) => any;
type F6 = ({ a: string }: {
a: any;
}) => typeof string;
type F7 = ({ a, b: number }: {
a: any;
b: any;
}) => typeof number;
type F8 = ({ a, b: number }: {
a: any;
b: any;
}) => typeof number;
type F9 = ([a, b, c]: [any, any, any]) => void;
type G1 = new (arg: number) => any;
type G2 = new ({ a }: O) => any;
type G3 = new ({ a, b, c }: O) => any;
type G4 = new ({ a }: O) => any;
type G5 = new ({ a, b, c }: O) => any;
type G6 = new ({ a: string }: {
a: any;
}) => typeof string;
type G7 = new ({ a, b: number }: {
a: any;
b: any;
}) => typeof number;
type G8 = new ({ a, b: number }: {
a: any;
b: any;
}) => typeof number;
type G9 = new ([a, b, c]: [any, any, any]) => void;
type F10 = ({ "a": string }: {
a: any;
}) => void;
type F11 = ({ 2: string }: {
2: any;
}) => void;
type F12 = ({ ["a"]: string }: O) => void;
type F13 = ({ [2]: string }: {
2: any;
}) => void;
type G10 = new ({ "a": string }: {
a: any;
}) => void;
type G11 = new ({ 2: string }: {
2: any;
}) => void;
type G12 = new ({ ["a"]: string }: O) => void;
type G13 = new ({ [2]: string }: {
2: any;
}) => void;
interface I {
method1(arg: number): any;
method2({ a }: {
a: any;
}): any;
(arg: number): any;
({ a }: {
a: any;
}): any;
new (arg: number): any;
new ({ a }: {
a: any;
}): any;
}
declare function f1({ a }: O): void;
declare const f2: ({ a: string }: O) => void;
declare const f3: ({ a: string, b, c }: O) => void;
declare const f4: ({ a: string }: O) => string;
declare const f5: ({ a: string, b, c }: O) => string;
declare const obj1: {
method({ a: string }: O): void;
};
declare const obj2: {
method({ a: string }: O): string;
};
declare function f6({ a }: O): void;
declare const f7: ({ a: string, b, c }: O) => void;
declare const f8: ({ "a": string }: O) => void;
declare function f9({ 2: string }: {
2: any;
}): void;
declare function f10({ ["a"]: string }: O): void;
declare const f11: ({ [2]: string }: {
2: any;
}) => void;
declare function f12({ a: string }: O): typeof string;
|