mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Forbid unused property renaming in destructuring binding in function types (#41044)
* Forbid renaming a propertyin function type parameters
* add tests
* Remove renaming from declaration output
* accept baseline
* accept baseline
* renew tests (not very right now)
* get correct result
* update diagnostic text
* accept baseline
* add declaration emit test
* fix declaration emit
* fix formatting
* revert unnecessary change
* accept baseline
* extend tests
* Revert "revert unnecessary change"
This reverts commit 17a29fff6c.
* accept baseline
* Rename and refactor potentialAlways... stuff
* add non-identifier names
* extend check to non-identifier original property names
* update diagnostic message
* add related span
* accept baseline
* add symbol-keyed test case
* oops?
* workaround for unstable test
* fix suggested name
* add comment about non-identifier property names
* simplify isReferenced check
* accept baseline
* move it one step further
This commit is contained in:
+55
-9
@@ -1015,6 +1015,7 @@ namespace ts {
|
||||
const potentialNewTargetCollisions: Node[] = [];
|
||||
const potentialWeakMapSetCollisions: Node[] = [];
|
||||
const potentialReflectCollisions: Node[] = [];
|
||||
const potentialUnusedRenamedBindingElementsInTypes: BindingElement[] = [];
|
||||
const awaitedTypeStack: number[] = [];
|
||||
|
||||
const diagnostics = createDiagnosticCollection();
|
||||
@@ -5945,19 +5946,29 @@ namespace ts {
|
||||
return parameterNode;
|
||||
|
||||
function cloneBindingName(node: BindingName): BindingName {
|
||||
return elideInitializerAndSetEmitFlags(node) as BindingName;
|
||||
function elideInitializerAndSetEmitFlags(node: Node): Node {
|
||||
return elideInitializerAndPropertyRenamingAndSetEmitFlags(node) as BindingName;
|
||||
function elideInitializerAndPropertyRenamingAndSetEmitFlags(node: Node): Node {
|
||||
if (context.tracker.trackSymbol && isComputedPropertyName(node) && isLateBindableName(node)) {
|
||||
trackComputedName(node.expression, context.enclosingDeclaration, context);
|
||||
}
|
||||
let visited = visitEachChild(node, elideInitializerAndSetEmitFlags, nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndSetEmitFlags)!;
|
||||
let visited = visitEachChild(node, elideInitializerAndPropertyRenamingAndSetEmitFlags, nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndPropertyRenamingAndSetEmitFlags)!;
|
||||
if (isBindingElement(visited)) {
|
||||
visited = factory.updateBindingElement(
|
||||
visited,
|
||||
visited.dotDotDotToken,
|
||||
visited.propertyName,
|
||||
visited.name,
|
||||
/*initializer*/ undefined);
|
||||
if (visited.propertyName && isIdentifier(visited.propertyName) && isIdentifier(visited.name)) {
|
||||
visited = factory.updateBindingElement(
|
||||
visited,
|
||||
visited.dotDotDotToken,
|
||||
/* propertyName*/ undefined,
|
||||
visited.propertyName,
|
||||
/*initializer*/ undefined);
|
||||
}
|
||||
else {
|
||||
visited = factory.updateBindingElement(
|
||||
visited,
|
||||
visited.dotDotDotToken,
|
||||
visited.propertyName,
|
||||
visited.name,
|
||||
/*initializer*/ undefined);
|
||||
}
|
||||
}
|
||||
if (!nodeIsSynthesized(visited)) {
|
||||
visited = factory.cloneNode(visited);
|
||||
@@ -37432,6 +37443,24 @@ namespace ts {
|
||||
});
|
||||
}
|
||||
|
||||
function checkPotentialUncheckedRenamedBindingElementsInTypes() {
|
||||
for (const node of potentialUnusedRenamedBindingElementsInTypes) {
|
||||
if (!getSymbolOfNode(node)?.isReferenced) {
|
||||
const wrappingDeclaration = walkUpBindingElementsAndPatterns(node);
|
||||
Debug.assert(isParameterDeclaration(wrappingDeclaration), "Only parameter declaration should be checked here");
|
||||
const diagnostic = createDiagnosticForNode(node.name, Diagnostics._0_is_an_unused_renaming_of_1_Did_you_intend_to_use_it_as_a_type_annotation, declarationNameToString(node.name), declarationNameToString(node.propertyName));
|
||||
if (!wrappingDeclaration.type) {
|
||||
// entire parameter does not have type annotation, suggest adding an annotation
|
||||
addRelatedInfo(
|
||||
diagnostic,
|
||||
createFileDiagnostic(getSourceFileOfNode(wrappingDeclaration), wrappingDeclaration.end, 1, Diagnostics.We_can_only_write_a_type_for_0_by_adding_a_type_for_the_entire_parameter_here, declarationNameToString(node.propertyName))
|
||||
);
|
||||
}
|
||||
diagnostics.add(diagnostic);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function bindingNameText(name: BindingName): string {
|
||||
switch (name.kind) {
|
||||
case SyntaxKind.Identifier:
|
||||
@@ -37773,6 +37802,19 @@ namespace ts {
|
||||
}
|
||||
|
||||
if (isBindingElement(node)) {
|
||||
if (
|
||||
node.propertyName &&
|
||||
isIdentifier(node.name) &&
|
||||
isParameterDeclaration(node) &&
|
||||
nodeIsMissing((getContainingFunction(node) as FunctionLikeDeclaration).body)) {
|
||||
// type F = ({a: string}) => void;
|
||||
// ^^^^^^
|
||||
// variable renaming in function type notation is confusing,
|
||||
// so we forbid it even if noUnusedLocals is not enabled
|
||||
potentialUnusedRenamedBindingElementsInTypes.push(node);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isObjectBindingPattern(node.parent) && node.dotDotDotToken && languageVersion < ScriptTarget.ES2018) {
|
||||
checkExternalEmitHelpers(node, ExternalEmitHelpers.Rest);
|
||||
}
|
||||
@@ -41617,6 +41659,7 @@ namespace ts {
|
||||
clear(potentialNewTargetCollisions);
|
||||
clear(potentialWeakMapSetCollisions);
|
||||
clear(potentialReflectCollisions);
|
||||
clear(potentialUnusedRenamedBindingElementsInTypes);
|
||||
|
||||
forEach(node.statements, checkSourceElement);
|
||||
checkSourceElement(node.endOfFileToken);
|
||||
@@ -41636,6 +41679,9 @@ namespace ts {
|
||||
}
|
||||
});
|
||||
}
|
||||
if (!node.isDeclarationFile) {
|
||||
checkPotentialUncheckedRenamedBindingElementsInTypes();
|
||||
}
|
||||
});
|
||||
|
||||
if (compilerOptions.importsNotUsedAsValues === ImportsNotUsedAsValues.Error &&
|
||||
|
||||
@@ -3487,6 +3487,14 @@
|
||||
"category": "Error",
|
||||
"code": 2841
|
||||
},
|
||||
"'{0}' is an unused renaming of '{1}'. Did you intend to use it as a type annotation?": {
|
||||
"category": "Error",
|
||||
"code": 2842
|
||||
},
|
||||
"We can only write a type for '{0}' by adding a type for the entire parameter here.": {
|
||||
"category": "Error",
|
||||
"code": 2843
|
||||
},
|
||||
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
|
||||
@@ -453,7 +453,7 @@ namespace ts {
|
||||
return ret;
|
||||
}
|
||||
|
||||
function filterBindingPatternInitializers(name: BindingName) {
|
||||
function filterBindingPatternInitializersAndRenamings(name: BindingName) {
|
||||
if (name.kind === SyntaxKind.Identifier) {
|
||||
return name;
|
||||
}
|
||||
@@ -471,7 +471,23 @@ namespace ts {
|
||||
if (elem.kind === SyntaxKind.OmittedExpression) {
|
||||
return elem;
|
||||
}
|
||||
return factory.updateBindingElement(elem, elem.dotDotDotToken, elem.propertyName, filterBindingPatternInitializers(elem.name), shouldPrintWithInitializer(elem) ? elem.initializer : undefined);
|
||||
if (elem.propertyName && isIdentifier(elem.propertyName) && isIdentifier(elem.name) && !elem.symbol.isReferenced) {
|
||||
// Unnecessary property renaming is forbidden in types, so remove renaming
|
||||
return factory.updateBindingElement(
|
||||
elem,
|
||||
elem.dotDotDotToken,
|
||||
/* propertyName */ undefined,
|
||||
elem.propertyName,
|
||||
shouldPrintWithInitializer(elem) ? elem.initializer : undefined
|
||||
);
|
||||
}
|
||||
return factory.updateBindingElement(
|
||||
elem,
|
||||
elem.dotDotDotToken,
|
||||
elem.propertyName,
|
||||
filterBindingPatternInitializersAndRenamings(elem.name),
|
||||
shouldPrintWithInitializer(elem) ? elem.initializer : undefined
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -485,7 +501,7 @@ namespace ts {
|
||||
p,
|
||||
maskModifiers(p, modifierMask),
|
||||
p.dotDotDotToken,
|
||||
filterBindingPatternInitializers(p.name),
|
||||
filterBindingPatternInitializersAndRenamings(p.name),
|
||||
resolver.isOptionalParameter(p) ? (p.questionToken || factory.createToken(SyntaxKind.QuestionToken)) : undefined,
|
||||
ensureType(p, type || p.type, /*ignorePrivate*/ true), // Ignore private param props, since this type is going straight back into a param
|
||||
ensureNoInitializer(p)
|
||||
|
||||
@@ -5,7 +5,7 @@ interface Show {
|
||||
>x : number
|
||||
}
|
||||
function f({ show: showRename = v => v }: Show) {}
|
||||
>f : ({ show: showRename }: Show) => void
|
||||
>f : ({ show }: Show) => void
|
||||
>show : any
|
||||
>showRename : (x: number) => string
|
||||
>v => v : (v: number) => number
|
||||
@@ -32,7 +32,7 @@ interface Nested {
|
||||
>nested : Show
|
||||
}
|
||||
function ff({ nested: nestedRename = { show: v => v } }: Nested) {}
|
||||
>ff : ({ nested: nestedRename }: Nested) => void
|
||||
>ff : ({ nested }: Nested) => void
|
||||
>nested : any
|
||||
>nestedRename : Show
|
||||
>{ show: v => v } : { show: (v: number) => number; }
|
||||
|
||||
@@ -18,7 +18,7 @@ function f(_a, _b, _c) {
|
||||
|
||||
|
||||
//// [declarationEmitBindingPatterns.d.ts]
|
||||
declare const k: ({ x: z }: {
|
||||
declare const k: ({ x }: {
|
||||
x?: string;
|
||||
}) => void;
|
||||
declare var a: any;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
=== tests/cases/compiler/declarationEmitBindingPatterns.ts ===
|
||||
const k = ({x: z = 'y'}) => { }
|
||||
>k : ({ x: z }: { x?: string; }) => void
|
||||
>({x: z = 'y'}) => { } : ({ x: z }: { x?: string; }) => void
|
||||
>k : ({ x }: { x?: string; }) => void
|
||||
>({x: z = 'y'}) => { } : ({ x }: { x?: string; }) => void
|
||||
>x : any
|
||||
>z : string
|
||||
>'y' : "y"
|
||||
|
||||
@@ -417,7 +417,7 @@ function f13() {
|
||||
}
|
||||
|
||||
function f14([a = 1, [b = "hello", { x, y: c = false }]]) {
|
||||
>f14 : ([a, [b, { x, y: c }]]: [number, [string, { x: any; y?: boolean; }]]) => void
|
||||
>f14 : ([a, [b, { x, y }]]: [number, [string, { x: any; y?: boolean; }]]) => void
|
||||
>a : number
|
||||
>1 : 1
|
||||
>b : string
|
||||
@@ -438,7 +438,7 @@ function f14([a = 1, [b = "hello", { x, y: c = false }]]) {
|
||||
}
|
||||
f14([2, ["abc", { x: 0, y: true }]]);
|
||||
>f14([2, ["abc", { x: 0, y: true }]]) : void
|
||||
>f14 : ([a, [b, { x, y: c }]]: [number, [string, { x: any; y?: boolean; }]]) => void
|
||||
>f14 : ([a, [b, { x, y }]]: [number, [string, { x: any; y?: boolean; }]]) => void
|
||||
>[2, ["abc", { x: 0, y: true }]] : [number, [string, { x: number; y: true; }]]
|
||||
>2 : 2
|
||||
>["abc", { x: 0, y: true }] : [string, { x: number; y: true; }]
|
||||
@@ -451,7 +451,7 @@ f14([2, ["abc", { x: 0, y: true }]]);
|
||||
|
||||
f14([2, ["abc", { x: 0 }]]);
|
||||
>f14([2, ["abc", { x: 0 }]]) : void
|
||||
>f14 : ([a, [b, { x, y: c }]]: [number, [string, { x: any; y?: boolean; }]]) => void
|
||||
>f14 : ([a, [b, { x, y }]]: [number, [string, { x: any; y?: boolean; }]]) => void
|
||||
>[2, ["abc", { x: 0 }]] : [number, [string, { x: number; }]]
|
||||
>2 : 2
|
||||
>["abc", { x: 0 }] : [string, { x: number; }]
|
||||
@@ -462,7 +462,7 @@ f14([2, ["abc", { x: 0 }]]);
|
||||
|
||||
f14([2, ["abc", { y: false }]]); // Error, no x
|
||||
>f14([2, ["abc", { y: false }]]) : void
|
||||
>f14 : ([a, [b, { x, y: c }]]: [number, [string, { x: any; y?: boolean; }]]) => void
|
||||
>f14 : ([a, [b, { x, y }]]: [number, [string, { x: any; y?: boolean; }]]) => void
|
||||
>[2, ["abc", { y: false }]] : [number, [string, { y: false; }]]
|
||||
>2 : 2
|
||||
>["abc", { y: false }] : [string, { y: false; }]
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts(12,18): error TS2842: 'b' is an unused renaming of 'a'. Did you intend to use it as a type annotation?
|
||||
tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts(12,28): error TS2842: 'a' is an unused renaming of 'b'. Did you intend to use it as a type annotation?
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts (2 errors) ====
|
||||
interface a { a }
|
||||
interface b { b }
|
||||
interface c { c }
|
||||
|
||||
type T1 = ([a, b, c]);
|
||||
type F1 = ([a, b, c]) => void;
|
||||
|
||||
type T2 = ({ a });
|
||||
type F2 = ({ a }) => void;
|
||||
|
||||
type T3 = ([{ a: b }, { b: a }]);
|
||||
type F3 = ([{ a: b }, { b: a }]) => void;
|
||||
~
|
||||
!!! error TS2842: 'b' is an unused renaming of 'a'. Did you intend to use it as a type annotation?
|
||||
!!! related TS2843 tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts:12:32: We can only write a type for 'a' by adding a type for the entire parameter here.
|
||||
~
|
||||
!!! error TS2842: 'a' is an unused renaming of 'b'. Did you intend to use it as a type annotation?
|
||||
!!! related TS2843 tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts:12:32: We can only write a type for 'b' by adding a type for the entire parameter here.
|
||||
|
||||
type T4 = ([{ a: [b, c] }]);
|
||||
type F4 = ([{ a: [b, c] }]) => void;
|
||||
|
||||
type C1 = new ([{ a: [b, c] }]) => void;
|
||||
|
||||
var v1 = ([a, b, c]) => "hello";
|
||||
var v2: ([a, b, c]) => string;
|
||||
|
||||
@@ -52,7 +52,7 @@ declare type T3 = ([{
|
||||
}, {
|
||||
b: a;
|
||||
}]);
|
||||
declare type F3 = ([{ a: b }, { b: a }]: [{
|
||||
declare type F3 = ([{ a }, { b }]: [{
|
||||
a: any;
|
||||
}, {
|
||||
b: any;
|
||||
|
||||
@@ -31,7 +31,7 @@ type T3 = ([{ a: b }, { b: a }]);
|
||||
>b : a
|
||||
|
||||
type F3 = ([{ a: b }, { b: a }]) => void;
|
||||
>F3 : ([{ a: b }, { b: a }]: [{ a: any; }, { b: any; }]) => void
|
||||
>F3 : ([{ a }, { b }]: [{ a: any; }, { b: any; }]) => void
|
||||
>a : any
|
||||
>b : any
|
||||
>b : any
|
||||
|
||||
@@ -402,7 +402,7 @@ d5(); // Parameter is optional as its declaration included an initializer
|
||||
// Type annotations must instead be written on the top- level parameter declaration
|
||||
|
||||
function e1({x: number}) { } // x has type any NOT number
|
||||
>e1 : ({ x: number }: { x: any; }) => void
|
||||
>e1 : ({ x }: { x: any; }) => void
|
||||
>x : any
|
||||
>number : any
|
||||
|
||||
|
||||
@@ -402,7 +402,7 @@ d5(); // Parameter is optional as its declaration included an initializer
|
||||
// Type annotations must instead be written on the top- level parameter declaration
|
||||
|
||||
function e1({x: number}) { } // x has type any NOT number
|
||||
>e1 : ({ x: number }: { x: any; }) => void
|
||||
>e1 : ({ x }: { x: any; }) => void
|
||||
>x : any
|
||||
>number : any
|
||||
|
||||
|
||||
@@ -376,7 +376,7 @@ d5(); // Parameter is optional as its declaration included an initializer
|
||||
// Type annotations must instead be written on the top- level parameter declaration
|
||||
|
||||
function e1({x: number}) { } // x has type any NOT number
|
||||
>e1 : ({ x: number }: { x: any; }) => void
|
||||
>e1 : ({ x }: { x: any; }) => void
|
||||
>x : any
|
||||
>number : any
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
// Error
|
||||
function a({while}) { }
|
||||
>a : ({ while: }: { while: any; }) => void
|
||||
>a : ({ while }: { while: any; }) => void
|
||||
>while : any
|
||||
> : any
|
||||
|
||||
@@ -42,32 +42,32 @@ function a7(...a: string) { }
|
||||
|
||||
a({ while: 1 });
|
||||
>a({ while: 1 }) : void
|
||||
>a : ({ while: }: { while: any; }) => void
|
||||
>a : ({ while }: { while: any; }) => void
|
||||
>{ while: 1 } : { while: number; }
|
||||
>while : number
|
||||
>1 : 1
|
||||
|
||||
// No Error
|
||||
function b1({public: x}) { }
|
||||
>b1 : ({ public: x }: { public: any; }) => void
|
||||
>b1 : ({ public }: { public: any; }) => void
|
||||
>public : any
|
||||
>x : any
|
||||
|
||||
function b2({while: y}) { }
|
||||
>b2 : ({ while: y }: { while: any; }) => void
|
||||
>b2 : ({ while }: { while: any; }) => void
|
||||
>while : any
|
||||
>y : any
|
||||
|
||||
b1({ public: 1 });
|
||||
>b1({ public: 1 }) : void
|
||||
>b1 : ({ public: x }: { public: any; }) => void
|
||||
>b1 : ({ public }: { public: any; }) => void
|
||||
>{ public: 1 } : { public: number; }
|
||||
>public : number
|
||||
>1 : 1
|
||||
|
||||
b2({ while: 1 });
|
||||
>b2({ while: 1 }) : void
|
||||
>b2 : ({ while: y }: { while: any; }) => void
|
||||
>b2 : ({ while }: { while: any; }) => void
|
||||
>{ while: 1 } : { while: number; }
|
||||
>while : number
|
||||
>1 : 1
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
tests/cases/compiler/excessPropertyCheckWithSpread.ts(1,25): error TS2842: 'number' is an unused renaming of 'a'. Did you intend to use it as a type annotation?
|
||||
|
||||
|
||||
==== tests/cases/compiler/excessPropertyCheckWithSpread.ts (1 errors) ====
|
||||
declare function f({ a: number }): void
|
||||
~~~~~~
|
||||
!!! error TS2842: 'number' is an unused renaming of 'a'. Did you intend to use it as a type annotation?
|
||||
!!! related TS2843 tests/cases/compiler/excessPropertyCheckWithSpread.ts:1:33: We can only write a type for 'a' by adding a type for the entire parameter here.
|
||||
interface I {
|
||||
readonly n: number;
|
||||
}
|
||||
declare let i: I;
|
||||
f({ a: 1, ...i });
|
||||
|
||||
interface R {
|
||||
opt?: number
|
||||
}
|
||||
interface L {
|
||||
opt: string
|
||||
}
|
||||
declare let l: L;
|
||||
declare let r: R;
|
||||
f({ a: 1, ...l, ...r });
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
=== tests/cases/compiler/excessPropertyCheckWithSpread.ts ===
|
||||
declare function f({ a: number }): void
|
||||
>f : ({ a: number }: { a: any; }) => void
|
||||
>f : ({ a }: { a: any; }) => void
|
||||
>a : any
|
||||
>number : any
|
||||
|
||||
@@ -13,7 +13,7 @@ declare let i: I;
|
||||
|
||||
f({ a: 1, ...i });
|
||||
>f({ a: 1, ...i }) : void
|
||||
>f : ({ a: number }: { a: any; }) => void
|
||||
>f : ({ a }: { a: any; }) => void
|
||||
>{ a: 1, ...i } : { n: number; a: number; }
|
||||
>a : number
|
||||
>1 : 1
|
||||
@@ -35,7 +35,7 @@ declare let r: R;
|
||||
|
||||
f({ a: 1, ...l, ...r });
|
||||
>f({ a: 1, ...l, ...r }) : void
|
||||
>f : ({ a: number }: { a: any; }) => void
|
||||
>f : ({ a }: { a: any; }) => void
|
||||
>{ a: 1, ...l, ...r } : { opt: string | number; a: number; }
|
||||
>a : number
|
||||
>1 : 1
|
||||
|
||||
@@ -19,7 +19,7 @@ declare function suddenly(f: (a: { x: { z, ka }, y: string }) => void);
|
||||
suddenly(({ x: a, ...rest }) => rest.y);
|
||||
>suddenly(({ x: a, ...rest }) => rest.y) : any
|
||||
>suddenly : (f: (a: { x: { z: any; ka: any; }; y: string; }) => void) => any
|
||||
>({ x: a, ...rest }) => rest.y : ({ x: a, ...rest }: { x: { z: any; ka: any; }; y: string; }) => string
|
||||
>({ x: a, ...rest }) => rest.y : ({ x, ...rest }: { x: { z: any; ka: any; }; y: string; }) => string
|
||||
>x : any
|
||||
>a : { z: any; ka: any; }
|
||||
>rest : { y: string; }
|
||||
|
||||
@@ -19,7 +19,7 @@ declare function suddenly(f: (a: { x: { z, ka }, y: string }) => void);
|
||||
suddenly(({ x: a, ...rest }) => rest.y);
|
||||
>suddenly(({ x: a, ...rest }) => rest.y) : any
|
||||
>suddenly : (f: (a: { x: { z: any; ka: any; }; y: string; }) => void) => any
|
||||
>({ x: a, ...rest }) => rest.y : ({ x: a, ...rest }: { x: { z: any; ka: any; }; y: string; }) => string
|
||||
>({ x: a, ...rest }) => rest.y : ({ x, ...rest }: { x: { z: any; ka: any; }; y: string; }) => string
|
||||
>x : any
|
||||
>a : { z: any; ka: any; }
|
||||
>rest : { y: string; }
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
tests/cases/compiler/paramterDestrcuturingDeclaration.ts(2,10): error TS2842: 'name' is an unused renaming of 'p'. Did you intend to use it as a type annotation?
|
||||
tests/cases/compiler/paramterDestrcuturingDeclaration.ts(3,14): error TS2842: 'boolean' is an unused renaming of 'p'. Did you intend to use it as a type annotation?
|
||||
|
||||
|
||||
==== tests/cases/compiler/paramterDestrcuturingDeclaration.ts (2 errors) ====
|
||||
interface C {
|
||||
({p: name}): any;
|
||||
~~~~
|
||||
!!! error TS2842: 'name' is an unused renaming of 'p'. Did you intend to use it as a type annotation?
|
||||
!!! related TS2843 tests/cases/compiler/paramterDestrcuturingDeclaration.ts:2:15: We can only write a type for 'p' by adding a type for the entire parameter here.
|
||||
new ({p: boolean}): any;
|
||||
~~~~~~~
|
||||
!!! error TS2842: 'boolean' is an unused renaming of 'p'. Did you intend to use it as a type annotation?
|
||||
!!! related TS2843 tests/cases/compiler/paramterDestrcuturingDeclaration.ts:3:22: We can only write a type for 'p' by adding a type for the entire parameter here.
|
||||
}
|
||||
|
||||
@@ -10,10 +10,10 @@ interface C {
|
||||
|
||||
//// [paramterDestrcuturingDeclaration.d.ts]
|
||||
interface C {
|
||||
({ p: name }: {
|
||||
({ p }: {
|
||||
p: any;
|
||||
}): any;
|
||||
new ({ p: boolean }: {
|
||||
new ({ p }: {
|
||||
p: any;
|
||||
}): any;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(5,17): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation?
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(6,17): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation?
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(7,17): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation?
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(8,17): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation?
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(10,17): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation?
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(15,21): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation?
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(16,21): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation?
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(17,21): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation?
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(18,21): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation?
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(20,21): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation?
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(26,20): error TS2842: 'string' is an unused renaming of '"a"'. Did you intend to use it as a type annotation?
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(27,18): error TS2842: 'string' is an unused renaming of '2'. Did you intend to use it as a type annotation?
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(28,22): error TS2842: 'string' is an unused renaming of '["a"]'. Did you intend to use it as a type annotation?
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(29,20): error TS2842: 'string' is an unused renaming of '[2]'. Did you intend to use it as a type annotation?
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(30,24): error TS2842: 'string' is an unused renaming of '"a"'. Did you intend to use it as a type annotation?
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(31,22): error TS2842: 'string' is an unused renaming of '2'. Did you intend to use it as a type annotation?
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(32,26): error TS2842: 'string' is an unused renaming of '["a"]'. Did you intend to use it as a type annotation?
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(33,24): error TS2842: 'string' is an unused renaming of '[2]'. Did you intend to use it as a type annotation?
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(37,16): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation?
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(40,9): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation?
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(43,13): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation?
|
||||
|
||||
|
||||
==== tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts (21 errors) ====
|
||||
// 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
|
||||
~~~~~~
|
||||
!!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation?
|
||||
type F3 = ({ a: string, b, c }: O) => any; // Error
|
||||
~~~~~~
|
||||
!!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation?
|
||||
type F4 = ({ a: string }: O) => any; // Error
|
||||
~~~~~~
|
||||
!!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation?
|
||||
type F5 = ({ a: string, b, c }: O) => any; // Error
|
||||
~~~~~~
|
||||
!!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation?
|
||||
type F6 = ({ a: string }) => typeof string; // OK
|
||||
type F7 = ({ a: string, b: number }) => typeof number; // Error
|
||||
~~~~~~
|
||||
!!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation?
|
||||
!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:10:36: We can only write a type for 'a' by adding a type for the entire parameter here.
|
||||
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
|
||||
~~~~~~
|
||||
!!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation?
|
||||
type G3 = new ({ a: string, b, c }: O) => any; // Error
|
||||
~~~~~~
|
||||
!!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation?
|
||||
type G4 = new ({ a: string }: O) => any; // Error
|
||||
~~~~~~
|
||||
!!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation?
|
||||
type G5 = new ({ a: string, b, c }: O) => any; // Error
|
||||
~~~~~~
|
||||
!!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation?
|
||||
type G6 = new ({ a: string }) => typeof string; // OK
|
||||
type G7 = new ({ a: string, b: number }) => typeof number; // Error
|
||||
~~~~~~
|
||||
!!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation?
|
||||
!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:20:40: We can only write a type for 'a' by adding a type for the entire parameter here.
|
||||
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
|
||||
~~~~~~
|
||||
!!! error TS2842: 'string' is an unused renaming of '"a"'. Did you intend to use it as a type annotation?
|
||||
!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:26:28: We can only write a type for '"a"' by adding a type for the entire parameter here.
|
||||
type F11 = ({ 2: string }) => void; // Error
|
||||
~~~~~~
|
||||
!!! error TS2842: 'string' is an unused renaming of '2'. Did you intend to use it as a type annotation?
|
||||
!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:27:26: We can only write a type for '2' by adding a type for the entire parameter here.
|
||||
type F12 = ({ ["a"]: string }: O) => void; // Error
|
||||
~~~~~~
|
||||
!!! error TS2842: 'string' is an unused renaming of '["a"]'. Did you intend to use it as a type annotation?
|
||||
type F13 = ({ [2]: string }) => void; // Error
|
||||
~~~~~~
|
||||
!!! error TS2842: 'string' is an unused renaming of '[2]'. Did you intend to use it as a type annotation?
|
||||
!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:29:28: We can only write a type for '[2]' by adding a type for the entire parameter here.
|
||||
type G10 = new ({ "a": string }) => void; // Error
|
||||
~~~~~~
|
||||
!!! error TS2842: 'string' is an unused renaming of '"a"'. Did you intend to use it as a type annotation?
|
||||
!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:30:32: We can only write a type for '"a"' by adding a type for the entire parameter here.
|
||||
type G11 = new ({ 2: string }) => void; // Error
|
||||
~~~~~~
|
||||
!!! error TS2842: 'string' is an unused renaming of '2'. Did you intend to use it as a type annotation?
|
||||
!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:31:30: We can only write a type for '2' by adding a type for the entire parameter here.
|
||||
type G12 = new ({ ["a"]: string }: O) => void; // Error
|
||||
~~~~~~
|
||||
!!! error TS2842: 'string' is an unused renaming of '["a"]'. Did you intend to use it as a type annotation?
|
||||
type G13 = new ({ [2]: string }) => void; // Error
|
||||
~~~~~~
|
||||
!!! error TS2842: 'string' is an unused renaming of '[2]'. Did you intend to use it as a type annotation?
|
||||
!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:33:32: We can only write a type for '[2]' by adding a type for the entire parameter here.
|
||||
|
||||
interface I {
|
||||
method1(arg: number): any; // OK
|
||||
method2({ a: string }): any; // Error
|
||||
~~~~~~
|
||||
!!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation?
|
||||
!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:37:24: We can only write a type for 'a' by adding a type for the entire parameter here.
|
||||
|
||||
(arg: number): any; // OK
|
||||
({ a: string }): any; // Error
|
||||
~~~~~~
|
||||
!!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation?
|
||||
!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:40:17: We can only write a type for 'a' by adding a type for the entire parameter here.
|
||||
|
||||
new (arg: number): any; // OK
|
||||
new ({ a: string }): any; // Error
|
||||
~~~~~~
|
||||
!!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation?
|
||||
!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:43:21: We can only write a type for 'a' by adding a type for the entire parameter here.
|
||||
}
|
||||
|
||||
// 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"; }
|
||||
@@ -0,0 +1,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]
|
||||
declare type O = {
|
||||
a?: string;
|
||||
b: number;
|
||||
c: number;
|
||||
};
|
||||
declare type F1 = (arg: number) => any;
|
||||
declare type F2 = ({ a }: O) => any;
|
||||
declare type F3 = ({ a, b, c }: O) => any;
|
||||
declare type F4 = ({ a }: O) => any;
|
||||
declare type F5 = ({ a, b, c }: O) => any;
|
||||
declare type F6 = ({ a: string }: {
|
||||
a: any;
|
||||
}) => typeof string;
|
||||
declare type F7 = ({ a, b: number }: {
|
||||
a: any;
|
||||
b: any;
|
||||
}) => typeof number;
|
||||
declare type F8 = ({ a, b: number }: {
|
||||
a: any;
|
||||
b: any;
|
||||
}) => typeof number;
|
||||
declare type F9 = ([a, b, c]: [any, any, any]) => void;
|
||||
declare type G1 = new (arg: number) => any;
|
||||
declare type G2 = new ({ a }: O) => any;
|
||||
declare type G3 = new ({ a, b, c }: O) => any;
|
||||
declare type G4 = new ({ a }: O) => any;
|
||||
declare type G5 = new ({ a, b, c }: O) => any;
|
||||
declare type G6 = new ({ a: string }: {
|
||||
a: any;
|
||||
}) => typeof string;
|
||||
declare type G7 = new ({ a, b: number }: {
|
||||
a: any;
|
||||
b: any;
|
||||
}) => typeof number;
|
||||
declare type G8 = new ({ a, b: number }: {
|
||||
a: any;
|
||||
b: any;
|
||||
}) => typeof number;
|
||||
declare type G9 = new ([a, b, c]: [any, any, any]) => void;
|
||||
declare type F10 = ({ "a": string }: {
|
||||
a: any;
|
||||
}) => void;
|
||||
declare type F11 = ({ 2: string }: {
|
||||
2: any;
|
||||
}) => void;
|
||||
declare type F12 = ({ ["a"]: string }: O) => void;
|
||||
declare type F13 = ({ [2]: string }: {
|
||||
2: any;
|
||||
}) => void;
|
||||
declare type G10 = new ({ "a": string }: {
|
||||
a: any;
|
||||
}) => void;
|
||||
declare type G11 = new ({ 2: string }: {
|
||||
2: any;
|
||||
}) => void;
|
||||
declare type G12 = new ({ ["a"]: string }: O) => void;
|
||||
declare 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 }: O) => void;
|
||||
declare const f3: ({ a, b, c }: O) => void;
|
||||
declare const f4: ({ a }: O) => string;
|
||||
declare const f5: ({ a, b, c }: O) => string;
|
||||
declare const obj1: {
|
||||
method({ a }: O): void;
|
||||
};
|
||||
declare const obj2: {
|
||||
method({ a }: O): string;
|
||||
};
|
||||
declare function f6({ a }: O): void;
|
||||
declare const f7: ({ a, 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;
|
||||
@@ -0,0 +1,296 @@
|
||||
=== tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts ===
|
||||
// GH#37454, GH#41044
|
||||
|
||||
type O = { a?: string; b: number; c: number; };
|
||||
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
|
||||
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
|
||||
>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 22))
|
||||
>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 33))
|
||||
|
||||
type F1 = (arg: number) => any; // OK
|
||||
>F1 : Symbol(F1, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 47))
|
||||
>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 3, 11))
|
||||
|
||||
type F2 = ({ a: string }: O) => any; // Error
|
||||
>F2 : Symbol(F2, Decl(renamingDestructuredPropertyInFunctionType.ts, 3, 31))
|
||||
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 12))
|
||||
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
|
||||
|
||||
type F3 = ({ a: string, b, c }: O) => any; // Error
|
||||
>F3 : Symbol(F3, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 36))
|
||||
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 5, 12))
|
||||
>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 5, 23))
|
||||
>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 5, 26))
|
||||
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
|
||||
|
||||
type F4 = ({ a: string }: O) => any; // Error
|
||||
>F4 : Symbol(F4, Decl(renamingDestructuredPropertyInFunctionType.ts, 5, 42))
|
||||
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 6, 12))
|
||||
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
|
||||
|
||||
type F5 = ({ a: string, b, c }: O) => any; // Error
|
||||
>F5 : Symbol(F5, Decl(renamingDestructuredPropertyInFunctionType.ts, 6, 36))
|
||||
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 12))
|
||||
>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 23))
|
||||
>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 26))
|
||||
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
|
||||
|
||||
type F6 = ({ a: string }) => typeof string; // OK
|
||||
>F6 : Symbol(F6, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 42))
|
||||
>a : Symbol(a)
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 8, 12))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 8, 12))
|
||||
|
||||
type F7 = ({ a: string, b: number }) => typeof number; // Error
|
||||
>F7 : Symbol(F7, Decl(renamingDestructuredPropertyInFunctionType.ts, 8, 43))
|
||||
>a : Symbol(a)
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 12))
|
||||
>b : Symbol(b)
|
||||
>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 23))
|
||||
>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 23))
|
||||
|
||||
type F8 = ({ a, b: number }) => typeof number; // OK
|
||||
>F8 : Symbol(F8, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 54))
|
||||
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 10, 12))
|
||||
>b : Symbol(b)
|
||||
>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 10, 15))
|
||||
>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 10, 15))
|
||||
|
||||
type F9 = ([a, b, c]) => void; // OK
|
||||
>F9 : Symbol(F9, Decl(renamingDestructuredPropertyInFunctionType.ts, 10, 46))
|
||||
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 12))
|
||||
>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 14))
|
||||
>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 17))
|
||||
|
||||
type G1 = new (arg: number) => any; // OK
|
||||
>G1 : Symbol(G1, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 30))
|
||||
>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 13, 15))
|
||||
|
||||
type G2 = new ({ a: string }: O) => any; // Error
|
||||
>G2 : Symbol(G2, Decl(renamingDestructuredPropertyInFunctionType.ts, 13, 35))
|
||||
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 14, 16))
|
||||
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
|
||||
|
||||
type G3 = new ({ a: string, b, c }: O) => any; // Error
|
||||
>G3 : Symbol(G3, Decl(renamingDestructuredPropertyInFunctionType.ts, 14, 40))
|
||||
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 16))
|
||||
>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 27))
|
||||
>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 30))
|
||||
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
|
||||
|
||||
type G4 = new ({ a: string }: O) => any; // Error
|
||||
>G4 : Symbol(G4, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 46))
|
||||
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 16, 16))
|
||||
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
|
||||
|
||||
type G5 = new ({ a: string, b, c }: O) => any; // Error
|
||||
>G5 : Symbol(G5, Decl(renamingDestructuredPropertyInFunctionType.ts, 16, 40))
|
||||
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 16))
|
||||
>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 27))
|
||||
>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 30))
|
||||
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
|
||||
|
||||
type G6 = new ({ a: string }) => typeof string; // OK
|
||||
>G6 : Symbol(G6, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 46))
|
||||
>a : Symbol(a)
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 18, 16))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 18, 16))
|
||||
|
||||
type G7 = new ({ a: string, b: number }) => typeof number; // Error
|
||||
>G7 : Symbol(G7, Decl(renamingDestructuredPropertyInFunctionType.ts, 18, 47))
|
||||
>a : Symbol(a)
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 16))
|
||||
>b : Symbol(b)
|
||||
>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 27))
|
||||
>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 27))
|
||||
|
||||
type G8 = new ({ a, b: number }) => typeof number; // OK
|
||||
>G8 : Symbol(G8, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 58))
|
||||
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 20, 16))
|
||||
>b : Symbol(b)
|
||||
>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 20, 19))
|
||||
>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 20, 19))
|
||||
|
||||
type G9 = new ([a, b, c]) => void; // OK
|
||||
>G9 : Symbol(G9, Decl(renamingDestructuredPropertyInFunctionType.ts, 20, 50))
|
||||
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 16))
|
||||
>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 18))
|
||||
>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 21))
|
||||
|
||||
// Below are Error but renaming is retained in declaration emit,
|
||||
// since elinding it would leave invalid syntax.
|
||||
type F10 = ({ "a": string }) => void; // Error
|
||||
>F10 : Symbol(F10, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 34))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 25, 13))
|
||||
|
||||
type F11 = ({ 2: string }) => void; // Error
|
||||
>F11 : Symbol(F11, Decl(renamingDestructuredPropertyInFunctionType.ts, 25, 37))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 26, 13))
|
||||
|
||||
type F12 = ({ ["a"]: string }: O) => void; // Error
|
||||
>F12 : Symbol(F12, Decl(renamingDestructuredPropertyInFunctionType.ts, 26, 35))
|
||||
>"a" : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 27, 13))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 27, 13))
|
||||
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
|
||||
|
||||
type F13 = ({ [2]: string }) => void; // Error
|
||||
>F13 : Symbol(F13, Decl(renamingDestructuredPropertyInFunctionType.ts, 27, 42))
|
||||
>2 : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 28, 13))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 28, 13))
|
||||
|
||||
type G10 = new ({ "a": string }) => void; // Error
|
||||
>G10 : Symbol(G10, Decl(renamingDestructuredPropertyInFunctionType.ts, 28, 37))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 29, 17))
|
||||
|
||||
type G11 = new ({ 2: string }) => void; // Error
|
||||
>G11 : Symbol(G11, Decl(renamingDestructuredPropertyInFunctionType.ts, 29, 41))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 30, 17))
|
||||
|
||||
type G12 = new ({ ["a"]: string }: O) => void; // Error
|
||||
>G12 : Symbol(G12, Decl(renamingDestructuredPropertyInFunctionType.ts, 30, 39))
|
||||
>"a" : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 31, 17))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 31, 17))
|
||||
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
|
||||
|
||||
type G13 = new ({ [2]: string }) => void; // Error
|
||||
>G13 : Symbol(G13, Decl(renamingDestructuredPropertyInFunctionType.ts, 31, 46))
|
||||
>2 : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 32, 17))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 32, 17))
|
||||
|
||||
interface I {
|
||||
>I : Symbol(I, Decl(renamingDestructuredPropertyInFunctionType.ts, 32, 41))
|
||||
|
||||
method1(arg: number): any; // OK
|
||||
>method1 : Symbol(I.method1, Decl(renamingDestructuredPropertyInFunctionType.ts, 34, 13))
|
||||
>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 35, 10))
|
||||
|
||||
method2({ a: string }): any; // Error
|
||||
>method2 : Symbol(I.method2, Decl(renamingDestructuredPropertyInFunctionType.ts, 35, 28))
|
||||
>a : Symbol(a)
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 36, 11))
|
||||
|
||||
(arg: number): any; // OK
|
||||
>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 38, 3))
|
||||
|
||||
({ a: string }): any; // Error
|
||||
>a : Symbol(a)
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 39, 4))
|
||||
|
||||
new (arg: number): any; // OK
|
||||
>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 41, 7))
|
||||
|
||||
new ({ a: string }): any; // Error
|
||||
>a : Symbol(a)
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 42, 8))
|
||||
}
|
||||
|
||||
// Below are OK but renaming should be removed from declaration emit
|
||||
function f1({ a: string }: O) { }
|
||||
>f1 : Symbol(f1, Decl(renamingDestructuredPropertyInFunctionType.ts, 43, 1))
|
||||
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 46, 13))
|
||||
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
|
||||
|
||||
const f2 = function({ a: string }: O) { };
|
||||
>f2 : Symbol(f2, Decl(renamingDestructuredPropertyInFunctionType.ts, 47, 5))
|
||||
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 47, 21))
|
||||
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
|
||||
|
||||
const f3 = ({ a: string, b, c }: O) => { };
|
||||
>f3 : Symbol(f3, Decl(renamingDestructuredPropertyInFunctionType.ts, 48, 5))
|
||||
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 48, 13))
|
||||
>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 48, 24))
|
||||
>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 48, 27))
|
||||
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
|
||||
|
||||
const f4 = function({ a: string }: O): typeof string { return string; };
|
||||
>f4 : Symbol(f4, Decl(renamingDestructuredPropertyInFunctionType.ts, 49, 5))
|
||||
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 49, 21))
|
||||
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 49, 21))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 49, 21))
|
||||
|
||||
const f5 = ({ a: string, b, c }: O): typeof string => '';
|
||||
>f5 : Symbol(f5, Decl(renamingDestructuredPropertyInFunctionType.ts, 50, 5))
|
||||
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 50, 13))
|
||||
>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 50, 24))
|
||||
>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 50, 27))
|
||||
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 50, 13))
|
||||
|
||||
const obj1 = {
|
||||
>obj1 : Symbol(obj1, Decl(renamingDestructuredPropertyInFunctionType.ts, 51, 5))
|
||||
|
||||
method({ a: string }: O) { }
|
||||
>method : Symbol(method, Decl(renamingDestructuredPropertyInFunctionType.ts, 51, 14))
|
||||
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 52, 10))
|
||||
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
|
||||
|
||||
};
|
||||
const obj2 = {
|
||||
>obj2 : Symbol(obj2, Decl(renamingDestructuredPropertyInFunctionType.ts, 54, 5))
|
||||
|
||||
method({ a: string }: O): typeof string { return string; }
|
||||
>method : Symbol(method, Decl(renamingDestructuredPropertyInFunctionType.ts, 54, 14))
|
||||
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 55, 10))
|
||||
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 55, 10))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 55, 10))
|
||||
|
||||
};
|
||||
function f6({ a: string = "" }: O) { }
|
||||
>f6 : Symbol(f6, Decl(renamingDestructuredPropertyInFunctionType.ts, 56, 2))
|
||||
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 57, 13))
|
||||
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
|
||||
|
||||
const f7 = ({ a: string = "", b, c }: O) => { };
|
||||
>f7 : Symbol(f7, Decl(renamingDestructuredPropertyInFunctionType.ts, 58, 5))
|
||||
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 58, 13))
|
||||
>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 58, 29))
|
||||
>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 58, 32))
|
||||
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
|
||||
|
||||
const f8 = ({ "a": string }: O) => { };
|
||||
>f8 : Symbol(f8, Decl(renamingDestructuredPropertyInFunctionType.ts, 59, 5))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 59, 13))
|
||||
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
|
||||
|
||||
function f9 ({ 2: string }) { };
|
||||
>f9 : Symbol(f9, Decl(renamingDestructuredPropertyInFunctionType.ts, 59, 39))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 60, 14))
|
||||
|
||||
function f10 ({ ["a"]: string }: O) { };
|
||||
>f10 : Symbol(f10, Decl(renamingDestructuredPropertyInFunctionType.ts, 60, 32))
|
||||
>"a" : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 61, 15))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 61, 15))
|
||||
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
|
||||
|
||||
const f11 = ({ [2]: string }) => { };
|
||||
>f11 : Symbol(f11, Decl(renamingDestructuredPropertyInFunctionType.ts, 62, 5))
|
||||
>2 : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 62, 15))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 62, 15))
|
||||
|
||||
// In below case `string` should be kept because it is used
|
||||
function f12({ a: string = "" }: O): typeof string { return "a"; }
|
||||
>f12 : Symbol(f12, Decl(renamingDestructuredPropertyInFunctionType.ts, 62, 38))
|
||||
>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 65, 14))
|
||||
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 65, 14))
|
||||
|
||||
@@ -0,0 +1,286 @@
|
||||
=== tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts ===
|
||||
// GH#37454, GH#41044
|
||||
|
||||
type O = { a?: string; b: number; c: number; };
|
||||
>O : { a?: string; b: number; c: number; }
|
||||
>a : string
|
||||
>b : number
|
||||
>c : number
|
||||
|
||||
type F1 = (arg: number) => any; // OK
|
||||
>F1 : (arg: number) => any
|
||||
>arg : number
|
||||
|
||||
type F2 = ({ a: string }: O) => any; // Error
|
||||
>F2 : ({ a }: O) => any
|
||||
>a : any
|
||||
>string : string
|
||||
|
||||
type F3 = ({ a: string, b, c }: O) => any; // Error
|
||||
>F3 : ({ a, b, c }: O) => any
|
||||
>a : any
|
||||
>string : string
|
||||
>b : number
|
||||
>c : number
|
||||
|
||||
type F4 = ({ a: string }: O) => any; // Error
|
||||
>F4 : ({ a }: O) => any
|
||||
>a : any
|
||||
>string : string
|
||||
|
||||
type F5 = ({ a: string, b, c }: O) => any; // Error
|
||||
>F5 : ({ a, b, c }: O) => any
|
||||
>a : any
|
||||
>string : string
|
||||
>b : number
|
||||
>c : number
|
||||
|
||||
type F6 = ({ a: string }) => typeof string; // OK
|
||||
>F6 : ({ a }: { a: any; }) => any
|
||||
>a : any
|
||||
>string : any
|
||||
>string : any
|
||||
|
||||
type F7 = ({ a: string, b: number }) => typeof number; // Error
|
||||
>F7 : ({ a, b }: { a: any; b: any; }) => any
|
||||
>a : any
|
||||
>string : any
|
||||
>b : any
|
||||
>number : any
|
||||
>number : any
|
||||
|
||||
type F8 = ({ a, b: number }) => typeof number; // OK
|
||||
>F8 : ({ a, b }: { a: any; b: any; }) => any
|
||||
>a : any
|
||||
>b : any
|
||||
>number : any
|
||||
>number : any
|
||||
|
||||
type F9 = ([a, b, c]) => void; // OK
|
||||
>F9 : ([a, b, c]: [any, any, any]) => void
|
||||
>a : any
|
||||
>b : any
|
||||
>c : any
|
||||
|
||||
type G1 = new (arg: number) => any; // OK
|
||||
>G1 : new (arg: number) => any
|
||||
>arg : number
|
||||
|
||||
type G2 = new ({ a: string }: O) => any; // Error
|
||||
>G2 : new ({ a }: O) => any
|
||||
>a : any
|
||||
>string : string
|
||||
|
||||
type G3 = new ({ a: string, b, c }: O) => any; // Error
|
||||
>G3 : new ({ a, b, c }: O) => any
|
||||
>a : any
|
||||
>string : string
|
||||
>b : number
|
||||
>c : number
|
||||
|
||||
type G4 = new ({ a: string }: O) => any; // Error
|
||||
>G4 : new ({ a }: O) => any
|
||||
>a : any
|
||||
>string : string
|
||||
|
||||
type G5 = new ({ a: string, b, c }: O) => any; // Error
|
||||
>G5 : new ({ a, b, c }: O) => any
|
||||
>a : any
|
||||
>string : string
|
||||
>b : number
|
||||
>c : number
|
||||
|
||||
type G6 = new ({ a: string }) => typeof string; // OK
|
||||
>G6 : new ({ a }: { a: any; }) => any
|
||||
>a : any
|
||||
>string : any
|
||||
>string : any
|
||||
|
||||
type G7 = new ({ a: string, b: number }) => typeof number; // Error
|
||||
>G7 : new ({ a, b }: { a: any; b: any; }) => any
|
||||
>a : any
|
||||
>string : any
|
||||
>b : any
|
||||
>number : any
|
||||
>number : any
|
||||
|
||||
type G8 = new ({ a, b: number }) => typeof number; // OK
|
||||
>G8 : new ({ a, b }: { a: any; b: any; }) => any
|
||||
>a : any
|
||||
>b : any
|
||||
>number : any
|
||||
>number : any
|
||||
|
||||
type G9 = new ([a, b, c]) => void; // OK
|
||||
>G9 : new ([a, b, c]: [any, any, any]) => void
|
||||
>a : any
|
||||
>b : any
|
||||
>c : any
|
||||
|
||||
// Below are Error but renaming is retained in declaration emit,
|
||||
// since elinding it would leave invalid syntax.
|
||||
type F10 = ({ "a": string }) => void; // Error
|
||||
>F10 : ({ "a": string }: { a: any; }) => void
|
||||
>string : any
|
||||
|
||||
type F11 = ({ 2: string }) => void; // Error
|
||||
>F11 : ({ 2: string }: { 2: any; }) => void
|
||||
>string : any
|
||||
|
||||
type F12 = ({ ["a"]: string }: O) => void; // Error
|
||||
>F12 : ({ ["a"]: string }: O) => void
|
||||
>"a" : "a"
|
||||
>string : string
|
||||
|
||||
type F13 = ({ [2]: string }) => void; // Error
|
||||
>F13 : ({ [2]: string }: { 2: any; }) => void
|
||||
>2 : 2
|
||||
>string : any
|
||||
|
||||
type G10 = new ({ "a": string }) => void; // Error
|
||||
>G10 : new ({ "a": string }: { a: any; }) => void
|
||||
>string : any
|
||||
|
||||
type G11 = new ({ 2: string }) => void; // Error
|
||||
>G11 : new ({ 2: string }: { 2: any; }) => void
|
||||
>string : any
|
||||
|
||||
type G12 = new ({ ["a"]: string }: O) => void; // Error
|
||||
>G12 : new ({ ["a"]: string }: O) => void
|
||||
>"a" : "a"
|
||||
>string : string
|
||||
|
||||
type G13 = new ({ [2]: string }) => void; // Error
|
||||
>G13 : new ({ [2]: string }: { 2: any; }) => void
|
||||
>2 : 2
|
||||
>string : any
|
||||
|
||||
interface I {
|
||||
method1(arg: number): any; // OK
|
||||
>method1 : (arg: number) => any
|
||||
>arg : number
|
||||
|
||||
method2({ a: string }): any; // Error
|
||||
>method2 : ({ a }: { a: any; }) => any
|
||||
>a : any
|
||||
>string : any
|
||||
|
||||
(arg: number): any; // OK
|
||||
>arg : number
|
||||
|
||||
({ a: string }): any; // Error
|
||||
>a : any
|
||||
>string : any
|
||||
|
||||
new (arg: number): any; // OK
|
||||
>arg : number
|
||||
|
||||
new ({ a: string }): any; // Error
|
||||
>a : any
|
||||
>string : any
|
||||
}
|
||||
|
||||
// Below are OK but renaming should be removed from declaration emit
|
||||
function f1({ a: string }: O) { }
|
||||
>f1 : ({ a }: O) => void
|
||||
>a : any
|
||||
>string : string
|
||||
|
||||
const f2 = function({ a: string }: O) { };
|
||||
>f2 : ({ a }: O) => void
|
||||
>function({ a: string }: O) { } : ({ a }: O) => void
|
||||
>a : any
|
||||
>string : string
|
||||
|
||||
const f3 = ({ a: string, b, c }: O) => { };
|
||||
>f3 : ({ a, b, c }: O) => void
|
||||
>({ a: string, b, c }: O) => { } : ({ a, b, c }: O) => void
|
||||
>a : any
|
||||
>string : string
|
||||
>b : number
|
||||
>c : number
|
||||
|
||||
const f4 = function({ a: string }: O): typeof string { return string; };
|
||||
>f4 : ({ a }: O) => string
|
||||
>function({ a: string }: O): typeof string { return string; } : ({ a }: O) => string
|
||||
>a : any
|
||||
>string : string
|
||||
>string : string
|
||||
>string : string
|
||||
|
||||
const f5 = ({ a: string, b, c }: O): typeof string => '';
|
||||
>f5 : ({ a, b, c }: O) => string
|
||||
>({ a: string, b, c }: O): typeof string => '' : ({ a, b, c }: O) => string
|
||||
>a : any
|
||||
>string : string
|
||||
>b : number
|
||||
>c : number
|
||||
>string : string
|
||||
>'' : ""
|
||||
|
||||
const obj1 = {
|
||||
>obj1 : { method({ a }: O): void; }
|
||||
>{ method({ a: string }: O) { }} : { method({ a }: O): void; }
|
||||
|
||||
method({ a: string }: O) { }
|
||||
>method : ({ a }: O) => void
|
||||
>a : any
|
||||
>string : string
|
||||
|
||||
};
|
||||
const obj2 = {
|
||||
>obj2 : { method({ a }: O): string; }
|
||||
>{ method({ a: string }: O): typeof string { return string; }} : { method({ a }: O): string; }
|
||||
|
||||
method({ a: string }: O): typeof string { return string; }
|
||||
>method : ({ a }: O) => string
|
||||
>a : any
|
||||
>string : string
|
||||
>string : string
|
||||
>string : string
|
||||
|
||||
};
|
||||
function f6({ a: string = "" }: O) { }
|
||||
>f6 : ({ a }: O) => void
|
||||
>a : any
|
||||
>string : string
|
||||
>"" : ""
|
||||
|
||||
const f7 = ({ a: string = "", b, c }: O) => { };
|
||||
>f7 : ({ a, b, c }: O) => void
|
||||
>({ a: string = "", b, c }: O) => { } : ({ a, b, c }: O) => void
|
||||
>a : any
|
||||
>string : string
|
||||
>"" : ""
|
||||
>b : number
|
||||
>c : number
|
||||
|
||||
const f8 = ({ "a": string }: O) => { };
|
||||
>f8 : ({ "a": string }: O) => void
|
||||
>({ "a": string }: O) => { } : ({ "a": string }: O) => void
|
||||
>string : string
|
||||
|
||||
function f9 ({ 2: string }) { };
|
||||
>f9 : ({ 2: string }: { 2: any; }) => void
|
||||
>string : any
|
||||
|
||||
function f10 ({ ["a"]: string }: O) { };
|
||||
>f10 : ({ ["a"]: string }: O) => void
|
||||
>"a" : "a"
|
||||
>string : string
|
||||
|
||||
const f11 = ({ [2]: string }) => { };
|
||||
>f11 : ({ [2]: string }: { 2: any; }) => void
|
||||
>({ [2]: string }) => { } : ({ [2]: string }: { 2: any; }) => void
|
||||
>2 : 2
|
||||
>string : any
|
||||
|
||||
// In below case `string` should be kept because it is used
|
||||
function f12({ a: string = "" }: O): typeof string { return "a"; }
|
||||
>f12 : ({ a }: O) => typeof string
|
||||
>a : any
|
||||
>string : string
|
||||
>"" : ""
|
||||
>string : string
|
||||
>"a" : "a"
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
//// [renamingDestructuredPropertyInFunctionType2.ts]
|
||||
type F = ({a: string}) => void;
|
||||
|
||||
const f = ({a: string}) => string;
|
||||
|
||||
|
||||
|
||||
//// [renamingDestructuredPropertyInFunctionType2.js]
|
||||
var f = function (_a) {
|
||||
var string = _a.a;
|
||||
return string;
|
||||
};
|
||||
@@ -0,0 +1,153 @@
|
||||
=== tests/cases/compiler/a.d.ts ===
|
||||
type O = { a: string; b: number; c: number; };
|
||||
>O : Symbol(O, Decl(a.d.ts, 0, 0))
|
||||
>a : Symbol(a, Decl(a.d.ts, 0, 10))
|
||||
>b : Symbol(b, Decl(a.d.ts, 0, 21))
|
||||
>c : Symbol(c, Decl(a.d.ts, 0, 32))
|
||||
|
||||
type F1 = (arg: number) => any;
|
||||
>F1 : Symbol(F1, Decl(a.d.ts, 0, 46))
|
||||
>arg : Symbol(arg, Decl(a.d.ts, 1, 11))
|
||||
|
||||
type F2 = ({ a: string }: O) => any;
|
||||
>F2 : Symbol(F2, Decl(a.d.ts, 1, 31))
|
||||
>a : Symbol(a, Decl(a.d.ts, 0, 10))
|
||||
>string : Symbol(string, Decl(a.d.ts, 2, 12))
|
||||
>O : Symbol(O, Decl(a.d.ts, 0, 0))
|
||||
|
||||
type F3 = ({ a: string, b, c }: O) => any;
|
||||
>F3 : Symbol(F3, Decl(a.d.ts, 2, 36))
|
||||
>a : Symbol(a, Decl(a.d.ts, 0, 10))
|
||||
>string : Symbol(string, Decl(a.d.ts, 3, 12))
|
||||
>b : Symbol(b, Decl(a.d.ts, 3, 23))
|
||||
>c : Symbol(c, Decl(a.d.ts, 3, 26))
|
||||
>O : Symbol(O, Decl(a.d.ts, 0, 0))
|
||||
|
||||
type F4 = ({ a: string }: O) => any;
|
||||
>F4 : Symbol(F4, Decl(a.d.ts, 3, 42))
|
||||
>a : Symbol(a, Decl(a.d.ts, 0, 10))
|
||||
>string : Symbol(string, Decl(a.d.ts, 4, 12))
|
||||
>O : Symbol(O, Decl(a.d.ts, 0, 0))
|
||||
|
||||
type F5 = ({ a: string, b, c }: O) => any;
|
||||
>F5 : Symbol(F5, Decl(a.d.ts, 4, 36))
|
||||
>a : Symbol(a, Decl(a.d.ts, 0, 10))
|
||||
>string : Symbol(string, Decl(a.d.ts, 5, 12))
|
||||
>b : Symbol(b, Decl(a.d.ts, 5, 23))
|
||||
>c : Symbol(c, Decl(a.d.ts, 5, 26))
|
||||
>O : Symbol(O, Decl(a.d.ts, 0, 0))
|
||||
|
||||
type F6 = ({ a: string }) => typeof string;
|
||||
>F6 : Symbol(F6, Decl(a.d.ts, 5, 42))
|
||||
>a : Symbol(a)
|
||||
>string : Symbol(string, Decl(a.d.ts, 6, 12))
|
||||
>string : Symbol(string, Decl(a.d.ts, 6, 12))
|
||||
|
||||
type F7 = ({ a: string, b: number }) => typeof number;
|
||||
>F7 : Symbol(F7, Decl(a.d.ts, 6, 43))
|
||||
>a : Symbol(a)
|
||||
>string : Symbol(string, Decl(a.d.ts, 7, 12))
|
||||
>b : Symbol(b)
|
||||
>number : Symbol(number, Decl(a.d.ts, 7, 23))
|
||||
>number : Symbol(number, Decl(a.d.ts, 7, 23))
|
||||
|
||||
type F8 = ({ a, b: number }) => typeof number;
|
||||
>F8 : Symbol(F8, Decl(a.d.ts, 7, 54))
|
||||
>a : Symbol(a, Decl(a.d.ts, 8, 12))
|
||||
>b : Symbol(b)
|
||||
>number : Symbol(number, Decl(a.d.ts, 8, 15))
|
||||
>number : Symbol(number, Decl(a.d.ts, 8, 15))
|
||||
|
||||
type F9 = ([a, b, c]) => void;
|
||||
>F9 : Symbol(F9, Decl(a.d.ts, 8, 46))
|
||||
>a : Symbol(a, Decl(a.d.ts, 9, 12))
|
||||
>b : Symbol(b, Decl(a.d.ts, 9, 14))
|
||||
>c : Symbol(c, Decl(a.d.ts, 9, 17))
|
||||
|
||||
type G1 = (arg: number) => any;
|
||||
>G1 : Symbol(G1, Decl(a.d.ts, 9, 30))
|
||||
>arg : Symbol(arg, Decl(a.d.ts, 11, 11))
|
||||
|
||||
type G2 = ({ a: string }: O) => any;
|
||||
>G2 : Symbol(G2, Decl(a.d.ts, 11, 31))
|
||||
>a : Symbol(a, Decl(a.d.ts, 0, 10))
|
||||
>string : Symbol(string, Decl(a.d.ts, 12, 12))
|
||||
>O : Symbol(O, Decl(a.d.ts, 0, 0))
|
||||
|
||||
type G3 = ({ a: string, b, c }: O) => any;
|
||||
>G3 : Symbol(G3, Decl(a.d.ts, 12, 36))
|
||||
>a : Symbol(a, Decl(a.d.ts, 0, 10))
|
||||
>string : Symbol(string, Decl(a.d.ts, 13, 12))
|
||||
>b : Symbol(b, Decl(a.d.ts, 13, 23))
|
||||
>c : Symbol(c, Decl(a.d.ts, 13, 26))
|
||||
>O : Symbol(O, Decl(a.d.ts, 0, 0))
|
||||
|
||||
type G4 = ({ a: string }: O) => any;
|
||||
>G4 : Symbol(G4, Decl(a.d.ts, 13, 42))
|
||||
>a : Symbol(a, Decl(a.d.ts, 0, 10))
|
||||
>string : Symbol(string, Decl(a.d.ts, 14, 12))
|
||||
>O : Symbol(O, Decl(a.d.ts, 0, 0))
|
||||
|
||||
type G5 = ({ a: string, b, c }: O) => any;
|
||||
>G5 : Symbol(G5, Decl(a.d.ts, 14, 36))
|
||||
>a : Symbol(a, Decl(a.d.ts, 0, 10))
|
||||
>string : Symbol(string, Decl(a.d.ts, 15, 12))
|
||||
>b : Symbol(b, Decl(a.d.ts, 15, 23))
|
||||
>c : Symbol(c, Decl(a.d.ts, 15, 26))
|
||||
>O : Symbol(O, Decl(a.d.ts, 0, 0))
|
||||
|
||||
type G6 = ({ a: string }) => typeof string;
|
||||
>G6 : Symbol(G6, Decl(a.d.ts, 15, 42))
|
||||
>a : Symbol(a)
|
||||
>string : Symbol(string, Decl(a.d.ts, 16, 12))
|
||||
>string : Symbol(string, Decl(a.d.ts, 16, 12))
|
||||
|
||||
type G7 = ({ a: string, b: number }) => typeof number;
|
||||
>G7 : Symbol(G7, Decl(a.d.ts, 16, 43))
|
||||
>a : Symbol(a)
|
||||
>string : Symbol(string, Decl(a.d.ts, 17, 12))
|
||||
>b : Symbol(b)
|
||||
>number : Symbol(number, Decl(a.d.ts, 17, 23))
|
||||
>number : Symbol(number, Decl(a.d.ts, 17, 23))
|
||||
|
||||
type G8 = ({ a, b: number }) => typeof number;
|
||||
>G8 : Symbol(G8, Decl(a.d.ts, 17, 54))
|
||||
>a : Symbol(a, Decl(a.d.ts, 18, 12))
|
||||
>b : Symbol(b)
|
||||
>number : Symbol(number, Decl(a.d.ts, 18, 15))
|
||||
>number : Symbol(number, Decl(a.d.ts, 18, 15))
|
||||
|
||||
type G9 = ([a, b, c]) => void;
|
||||
>G9 : Symbol(G9, Decl(a.d.ts, 18, 46))
|
||||
>a : Symbol(a, Decl(a.d.ts, 19, 12))
|
||||
>b : Symbol(b, Decl(a.d.ts, 19, 14))
|
||||
>c : Symbol(c, Decl(a.d.ts, 19, 17))
|
||||
|
||||
interface I {
|
||||
>I : Symbol(I, Decl(a.d.ts, 19, 30))
|
||||
|
||||
method1(arg: number): any;
|
||||
>method1 : Symbol(I.method1, Decl(a.d.ts, 21, 13))
|
||||
>arg : Symbol(arg, Decl(a.d.ts, 22, 10))
|
||||
|
||||
method2({ a: string }): any;
|
||||
>method2 : Symbol(I.method2, Decl(a.d.ts, 22, 28))
|
||||
>a : Symbol(a)
|
||||
>string : Symbol(string, Decl(a.d.ts, 23, 11))
|
||||
|
||||
(arg: number): any;
|
||||
>arg : Symbol(arg, Decl(a.d.ts, 25, 3))
|
||||
|
||||
({ a: string }): any;
|
||||
>a : Symbol(a)
|
||||
>string : Symbol(string, Decl(a.d.ts, 26, 4))
|
||||
|
||||
new (arg: number): any;
|
||||
>arg : Symbol(arg, Decl(a.d.ts, 28, 7))
|
||||
|
||||
new ({ a: string }): any;
|
||||
>a : Symbol(a)
|
||||
>string : Symbol(string, Decl(a.d.ts, 29, 8))
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
=== tests/cases/compiler/a.d.ts ===
|
||||
type O = { a: string; b: number; c: number; };
|
||||
>O : { a: string; b: number; c: number; }
|
||||
>a : string
|
||||
>b : number
|
||||
>c : number
|
||||
|
||||
type F1 = (arg: number) => any;
|
||||
>F1 : (arg: number) => any
|
||||
>arg : number
|
||||
|
||||
type F2 = ({ a: string }: O) => any;
|
||||
>F2 : ({ a }: O) => any
|
||||
>a : any
|
||||
>string : string
|
||||
|
||||
type F3 = ({ a: string, b, c }: O) => any;
|
||||
>F3 : ({ a, b, c }: O) => any
|
||||
>a : any
|
||||
>string : string
|
||||
>b : number
|
||||
>c : number
|
||||
|
||||
type F4 = ({ a: string }: O) => any;
|
||||
>F4 : ({ a }: O) => any
|
||||
>a : any
|
||||
>string : string
|
||||
|
||||
type F5 = ({ a: string, b, c }: O) => any;
|
||||
>F5 : ({ a, b, c }: O) => any
|
||||
>a : any
|
||||
>string : string
|
||||
>b : number
|
||||
>c : number
|
||||
|
||||
type F6 = ({ a: string }) => typeof string;
|
||||
>F6 : ({ a }: { a: any; }) => any
|
||||
>a : any
|
||||
>string : any
|
||||
>string : any
|
||||
|
||||
type F7 = ({ a: string, b: number }) => typeof number;
|
||||
>F7 : ({ a, b }: { a: any; b: any; }) => any
|
||||
>a : any
|
||||
>string : any
|
||||
>b : any
|
||||
>number : any
|
||||
>number : any
|
||||
|
||||
type F8 = ({ a, b: number }) => typeof number;
|
||||
>F8 : ({ a, b }: { a: any; b: any; }) => any
|
||||
>a : any
|
||||
>b : any
|
||||
>number : any
|
||||
>number : any
|
||||
|
||||
type F9 = ([a, b, c]) => void;
|
||||
>F9 : ([a, b, c]: [any, any, any]) => void
|
||||
>a : any
|
||||
>b : any
|
||||
>c : any
|
||||
|
||||
type G1 = (arg: number) => any;
|
||||
>G1 : (arg: number) => any
|
||||
>arg : number
|
||||
|
||||
type G2 = ({ a: string }: O) => any;
|
||||
>G2 : ({ a }: O) => any
|
||||
>a : any
|
||||
>string : string
|
||||
|
||||
type G3 = ({ a: string, b, c }: O) => any;
|
||||
>G3 : ({ a, b, c }: O) => any
|
||||
>a : any
|
||||
>string : string
|
||||
>b : number
|
||||
>c : number
|
||||
|
||||
type G4 = ({ a: string }: O) => any;
|
||||
>G4 : ({ a }: O) => any
|
||||
>a : any
|
||||
>string : string
|
||||
|
||||
type G5 = ({ a: string, b, c }: O) => any;
|
||||
>G5 : ({ a, b, c }: O) => any
|
||||
>a : any
|
||||
>string : string
|
||||
>b : number
|
||||
>c : number
|
||||
|
||||
type G6 = ({ a: string }) => typeof string;
|
||||
>G6 : ({ a }: { a: any; }) => any
|
||||
>a : any
|
||||
>string : any
|
||||
>string : any
|
||||
|
||||
type G7 = ({ a: string, b: number }) => typeof number;
|
||||
>G7 : ({ a, b }: { a: any; b: any; }) => any
|
||||
>a : any
|
||||
>string : any
|
||||
>b : any
|
||||
>number : any
|
||||
>number : any
|
||||
|
||||
type G8 = ({ a, b: number }) => typeof number;
|
||||
>G8 : ({ a, b }: { a: any; b: any; }) => any
|
||||
>a : any
|
||||
>b : any
|
||||
>number : any
|
||||
>number : any
|
||||
|
||||
type G9 = ([a, b, c]) => void;
|
||||
>G9 : ([a, b, c]: [any, any, any]) => void
|
||||
>a : any
|
||||
>b : any
|
||||
>c : any
|
||||
|
||||
interface I {
|
||||
method1(arg: number): any;
|
||||
>method1 : (arg: number) => any
|
||||
>arg : number
|
||||
|
||||
method2({ a: string }): any;
|
||||
>method2 : ({ a }: { a: any; }) => any
|
||||
>a : any
|
||||
>string : any
|
||||
|
||||
(arg: number): any;
|
||||
>arg : number
|
||||
|
||||
({ a: string }): any;
|
||||
>a : any
|
||||
>string : any
|
||||
|
||||
new (arg: number): any;
|
||||
>arg : number
|
||||
|
||||
new ({ a: string }): any;
|
||||
>a : any
|
||||
>string : any
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType3.ts(3,22): error TS2842: 'string' is an unused renaming of '[sym]'. Did you intend to use it as a type annotation?
|
||||
tests/cases/compiler/renamingDestructuredPropertyInFunctionType3.ts(4,26): error TS2842: 'string' is an unused renaming of '[sym]'. Did you intend to use it as a type annotation?
|
||||
|
||||
|
||||
==== tests/cases/compiler/renamingDestructuredPropertyInFunctionType3.ts (2 errors) ====
|
||||
const sym = Symbol();
|
||||
type O = Record<symbol, unknown>
|
||||
type F14 = ({ [sym]: string }: O) => void; // Error
|
||||
~~~~~~
|
||||
!!! error TS2842: 'string' is an unused renaming of '[sym]'. Did you intend to use it as a type annotation?
|
||||
type G14 = new ({ [sym]: string }: O) => void; // Error
|
||||
~~~~~~
|
||||
!!! error TS2842: 'string' is an unused renaming of '[sym]'. Did you intend to use it as a type annotation?
|
||||
|
||||
const f13 = ({ [sym]: string }: O) => { };
|
||||
function f14 ({ [sym]: string }: O) { };
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
//// [renamingDestructuredPropertyInFunctionType3.ts]
|
||||
const sym = Symbol();
|
||||
type O = Record<symbol, unknown>
|
||||
type F14 = ({ [sym]: string }: O) => void; // Error
|
||||
type G14 = new ({ [sym]: string }: O) => void; // Error
|
||||
|
||||
const f13 = ({ [sym]: string }: O) => { };
|
||||
function f14 ({ [sym]: string }: O) { };
|
||||
|
||||
|
||||
//// [renamingDestructuredPropertyInFunctionType3.js]
|
||||
const sym = Symbol();
|
||||
const f13 = ({ [sym]: string }) => { };
|
||||
function f14({ [sym]: string }) { }
|
||||
;
|
||||
@@ -0,0 +1,33 @@
|
||||
=== tests/cases/compiler/renamingDestructuredPropertyInFunctionType3.ts ===
|
||||
const sym = Symbol();
|
||||
>sym : Symbol(sym, Decl(renamingDestructuredPropertyInFunctionType3.ts, 0, 5))
|
||||
>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
|
||||
|
||||
type O = Record<symbol, unknown>
|
||||
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType3.ts, 0, 21))
|
||||
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
|
||||
|
||||
type F14 = ({ [sym]: string }: O) => void; // Error
|
||||
>F14 : Symbol(F14, Decl(renamingDestructuredPropertyInFunctionType3.ts, 1, 32))
|
||||
>sym : Symbol(sym, Decl(renamingDestructuredPropertyInFunctionType3.ts, 0, 5))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType3.ts, 2, 13))
|
||||
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType3.ts, 0, 21))
|
||||
|
||||
type G14 = new ({ [sym]: string }: O) => void; // Error
|
||||
>G14 : Symbol(G14, Decl(renamingDestructuredPropertyInFunctionType3.ts, 2, 42))
|
||||
>sym : Symbol(sym, Decl(renamingDestructuredPropertyInFunctionType3.ts, 0, 5))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType3.ts, 3, 17))
|
||||
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType3.ts, 0, 21))
|
||||
|
||||
const f13 = ({ [sym]: string }: O) => { };
|
||||
>f13 : Symbol(f13, Decl(renamingDestructuredPropertyInFunctionType3.ts, 5, 5))
|
||||
>sym : Symbol(sym, Decl(renamingDestructuredPropertyInFunctionType3.ts, 0, 5))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType3.ts, 5, 15))
|
||||
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType3.ts, 0, 21))
|
||||
|
||||
function f14 ({ [sym]: string }: O) { };
|
||||
>f14 : Symbol(f14, Decl(renamingDestructuredPropertyInFunctionType3.ts, 5, 43))
|
||||
>sym : Symbol(sym, Decl(renamingDestructuredPropertyInFunctionType3.ts, 0, 5))
|
||||
>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType3.ts, 6, 15))
|
||||
>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType3.ts, 0, 21))
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
=== tests/cases/compiler/renamingDestructuredPropertyInFunctionType3.ts ===
|
||||
const sym = Symbol();
|
||||
>sym : unique symbol
|
||||
>Symbol() : unique symbol
|
||||
>Symbol : SymbolConstructor
|
||||
|
||||
type O = Record<symbol, unknown>
|
||||
>O : { [x: symbol]: unknown; }
|
||||
|
||||
type F14 = ({ [sym]: string }: O) => void; // Error
|
||||
>F14 : ({ [sym]: string }: O) => void
|
||||
>sym : unique symbol
|
||||
>string : unknown
|
||||
|
||||
type G14 = new ({ [sym]: string }: O) => void; // Error
|
||||
>G14 : new ({ [sym]: string }: O) => void
|
||||
>sym : unique symbol
|
||||
>string : unknown
|
||||
|
||||
const f13 = ({ [sym]: string }: O) => { };
|
||||
>f13 : ({ [sym]: string }: O) => void
|
||||
>({ [sym]: string }: O) => { } : ({ [sym]: string }: O) => void
|
||||
>sym : unique symbol
|
||||
>string : unknown
|
||||
|
||||
function f14 ({ [sym]: string }: O) { };
|
||||
>f14 : ({ [sym]: string }: O) => void
|
||||
>sym : unique symbol
|
||||
>string : unknown
|
||||
|
||||
+6
-6
@@ -34,7 +34,7 @@ var robotA: Robot = { name: "mower", skills: { primary: "mowing", secondary: "no
|
||||
>"none" : "none"
|
||||
|
||||
function foo1({ skills: { primary: primaryA, secondary: secondaryA } }: Robot) {
|
||||
>foo1 : ({ skills: { primary: primaryA, secondary: secondaryA } }: Robot) => void
|
||||
>foo1 : ({ skills: { primary, secondary } }: Robot) => void
|
||||
>skills : any
|
||||
>primary : any
|
||||
>primaryA : string
|
||||
@@ -49,7 +49,7 @@ function foo1({ skills: { primary: primaryA, secondary: secondaryA } }: Robot) {
|
||||
>primaryA : string
|
||||
}
|
||||
function foo2({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }: Robot) {
|
||||
>foo2 : ({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }: Robot) => void
|
||||
>foo2 : ({ name, skills: { primary, secondary } }: Robot) => void
|
||||
>name : any
|
||||
>nameC : string
|
||||
>skills : any
|
||||
@@ -81,12 +81,12 @@ function foo3({ skills }: Robot) {
|
||||
|
||||
foo1(robotA);
|
||||
>foo1(robotA) : void
|
||||
>foo1 : ({ skills: { primary: primaryA, secondary: secondaryA } }: Robot) => void
|
||||
>foo1 : ({ skills: { primary, secondary } }: Robot) => void
|
||||
>robotA : Robot
|
||||
|
||||
foo1({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } });
|
||||
>foo1({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }) : void
|
||||
>foo1 : ({ skills: { primary: primaryA, secondary: secondaryA } }: Robot) => void
|
||||
>foo1 : ({ skills: { primary, secondary } }: Robot) => void
|
||||
>{ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } } : { name: string; skills: { primary: string; secondary: string; }; }
|
||||
>name : string
|
||||
>"Edger" : "Edger"
|
||||
@@ -99,12 +99,12 @@ foo1({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming"
|
||||
|
||||
foo2(robotA);
|
||||
>foo2(robotA) : void
|
||||
>foo2 : ({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }: Robot) => void
|
||||
>foo2 : ({ name, skills: { primary, secondary } }: Robot) => void
|
||||
>robotA : Robot
|
||||
|
||||
foo2({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } });
|
||||
>foo2({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }) : void
|
||||
>foo2 : ({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }: Robot) => void
|
||||
>foo2 : ({ name, skills: { primary, secondary } }: Robot) => void
|
||||
>{ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } } : { name: string; skills: { primary: string; secondary: string; }; }
|
||||
>name : string
|
||||
>"Edger" : "Edger"
|
||||
|
||||
+6
-6
@@ -34,7 +34,7 @@ var robotA: Robot = { name: "mower", skills: { primary: "mowing", secondary: "no
|
||||
>"none" : "none"
|
||||
|
||||
function foo1(
|
||||
>foo1 : ({ skills: { primary: primaryA, secondary: secondaryA } }?: Robot) => void
|
||||
>foo1 : ({ skills: { primary, secondary } }?: Robot) => void
|
||||
{
|
||||
skills: {
|
||||
>skills : any
|
||||
@@ -67,7 +67,7 @@ function foo1(
|
||||
>primaryA : string
|
||||
}
|
||||
function foo2(
|
||||
>foo2 : ({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }?: Robot) => void
|
||||
>foo2 : ({ name, skills: { primary, secondary } }?: Robot) => void
|
||||
{
|
||||
name: nameC = "name",
|
||||
>name : any
|
||||
@@ -126,12 +126,12 @@ function foo3({ skills = { primary: "SomeSkill", secondary: "someSkill" } }: Ro
|
||||
|
||||
foo1(robotA);
|
||||
>foo1(robotA) : void
|
||||
>foo1 : ({ skills: { primary: primaryA, secondary: secondaryA } }?: Robot) => void
|
||||
>foo1 : ({ skills: { primary, secondary } }?: Robot) => void
|
||||
>robotA : Robot
|
||||
|
||||
foo1({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } });
|
||||
>foo1({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }) : void
|
||||
>foo1 : ({ skills: { primary: primaryA, secondary: secondaryA } }?: Robot) => void
|
||||
>foo1 : ({ skills: { primary, secondary } }?: Robot) => void
|
||||
>{ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } } : { name: string; skills: { primary: string; secondary: string; }; }
|
||||
>name : string
|
||||
>"Edger" : "Edger"
|
||||
@@ -144,12 +144,12 @@ foo1({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming"
|
||||
|
||||
foo2(robotA);
|
||||
>foo2(robotA) : void
|
||||
>foo2 : ({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }?: Robot) => void
|
||||
>foo2 : ({ name, skills: { primary, secondary } }?: Robot) => void
|
||||
>robotA : Robot
|
||||
|
||||
foo2({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } });
|
||||
>foo2({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }) : void
|
||||
>foo2 : ({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }?: Robot) => void
|
||||
>foo2 : ({ name, skills: { primary, secondary } }?: Robot) => void
|
||||
>{ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } } : { name: string; skills: { primary: string; secondary: string; }; }
|
||||
>name : string
|
||||
>"Edger" : "Edger"
|
||||
|
||||
+6
-6
@@ -26,7 +26,7 @@ var robotA: Robot = { name: "mower", skill: "mowing" };
|
||||
>"mowing" : "mowing"
|
||||
|
||||
function foo1({ name: nameA }: Robot) {
|
||||
>foo1 : ({ name: nameA }: Robot) => void
|
||||
>foo1 : ({ name }: Robot) => void
|
||||
>name : any
|
||||
>nameA : string
|
||||
|
||||
@@ -38,7 +38,7 @@ function foo1({ name: nameA }: Robot) {
|
||||
>nameA : string
|
||||
}
|
||||
function foo2({ name: nameB, skill: skillB }: Robot) {
|
||||
>foo2 : ({ name: nameB, skill: skillB }: Robot) => void
|
||||
>foo2 : ({ name, skill }: Robot) => void
|
||||
>name : any
|
||||
>nameB : string
|
||||
>skill : any
|
||||
@@ -65,12 +65,12 @@ function foo3({ name }: Robot) {
|
||||
|
||||
foo1(robotA);
|
||||
>foo1(robotA) : void
|
||||
>foo1 : ({ name: nameA }: Robot) => void
|
||||
>foo1 : ({ name }: Robot) => void
|
||||
>robotA : Robot
|
||||
|
||||
foo1({ name: "Edger", skill: "cutting edges" });
|
||||
>foo1({ name: "Edger", skill: "cutting edges" }) : void
|
||||
>foo1 : ({ name: nameA }: Robot) => void
|
||||
>foo1 : ({ name }: Robot) => void
|
||||
>{ name: "Edger", skill: "cutting edges" } : { name: string; skill: string; }
|
||||
>name : string
|
||||
>"Edger" : "Edger"
|
||||
@@ -79,12 +79,12 @@ foo1({ name: "Edger", skill: "cutting edges" });
|
||||
|
||||
foo2(robotA);
|
||||
>foo2(robotA) : void
|
||||
>foo2 : ({ name: nameB, skill: skillB }: Robot) => void
|
||||
>foo2 : ({ name, skill }: Robot) => void
|
||||
>robotA : Robot
|
||||
|
||||
foo2({ name: "Edger", skill: "cutting edges" });
|
||||
>foo2({ name: "Edger", skill: "cutting edges" }) : void
|
||||
>foo2 : ({ name: nameB, skill: skillB }: Robot) => void
|
||||
>foo2 : ({ name, skill }: Robot) => void
|
||||
>{ name: "Edger", skill: "cutting edges" } : { name: string; skill: string; }
|
||||
>name : string
|
||||
>"Edger" : "Edger"
|
||||
|
||||
+6
-6
@@ -26,7 +26,7 @@ var robotA: Robot = { name: "mower", skill: "mowing" };
|
||||
>"mowing" : "mowing"
|
||||
|
||||
function foo1({ name: nameA = "<NoName>" }: Robot = { }) {
|
||||
>foo1 : ({ name: nameA }?: Robot) => void
|
||||
>foo1 : ({ name }?: Robot) => void
|
||||
>name : any
|
||||
>nameA : string
|
||||
>"<NoName>" : "<NoName>"
|
||||
@@ -40,7 +40,7 @@ function foo1({ name: nameA = "<NoName>" }: Robot = { }) {
|
||||
>nameA : string
|
||||
}
|
||||
function foo2({ name: nameB = "<NoName>", skill: skillB = "noSkill" }: Robot = {}) {
|
||||
>foo2 : ({ name: nameB, skill: skillB }?: Robot) => void
|
||||
>foo2 : ({ name, skill }?: Robot) => void
|
||||
>name : any
|
||||
>nameB : string
|
||||
>"<NoName>" : "<NoName>"
|
||||
@@ -72,12 +72,12 @@ function foo3({ name = "<NoName>" }: Robot = {}) {
|
||||
|
||||
foo1(robotA);
|
||||
>foo1(robotA) : void
|
||||
>foo1 : ({ name: nameA }?: Robot) => void
|
||||
>foo1 : ({ name }?: Robot) => void
|
||||
>robotA : Robot
|
||||
|
||||
foo1({ name: "Edger", skill: "cutting edges" });
|
||||
>foo1({ name: "Edger", skill: "cutting edges" }) : void
|
||||
>foo1 : ({ name: nameA }?: Robot) => void
|
||||
>foo1 : ({ name }?: Robot) => void
|
||||
>{ name: "Edger", skill: "cutting edges" } : { name: string; skill: string; }
|
||||
>name : string
|
||||
>"Edger" : "Edger"
|
||||
@@ -86,12 +86,12 @@ foo1({ name: "Edger", skill: "cutting edges" });
|
||||
|
||||
foo2(robotA);
|
||||
>foo2(robotA) : void
|
||||
>foo2 : ({ name: nameB, skill: skillB }?: Robot) => void
|
||||
>foo2 : ({ name, skill }?: Robot) => void
|
||||
>robotA : Robot
|
||||
|
||||
foo2({ name: "Edger", skill: "cutting edges" });
|
||||
>foo2({ name: "Edger", skill: "cutting edges" }) : void
|
||||
>foo2 : ({ name: nameB, skill: skillB }?: Robot) => void
|
||||
>foo2 : ({ name, skill }?: Robot) => void
|
||||
>{ name: "Edger", skill: "cutting edges" } : { name: string; skill: string; }
|
||||
>name : string
|
||||
>"Edger" : "Edger"
|
||||
|
||||
@@ -13,7 +13,7 @@ import("package").then(({default: foo}) => foo(42));
|
||||
>import("package") : Promise<{ default: (x: number) => string; }>
|
||||
>"package" : "package"
|
||||
>then : <TResult1 = { default: (x: number) => string; }, TResult2 = never>(onfulfilled?: (value: { default: (x: number) => string; }) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
|
||||
>({default: foo}) => foo(42) : ({ default: foo }: { default: (x: number) => string; }) => string
|
||||
>({default: foo}) => foo(42) : ({ default }: { default: (x: number) => string; }) => string
|
||||
>default : any
|
||||
>foo : (x: number) => string
|
||||
>foo(42) : string
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
tests/cases/conformance/jsx/file.tsx(17,39): error TS2842: 'string' is an unused renaming of 'y1'. Did you intend to use it as a type annotation?
|
||||
|
||||
|
||||
==== tests/cases/conformance/jsx/file.tsx (1 errors) ====
|
||||
import React = require('react')
|
||||
|
||||
declare function OneThing(k: {yxx: string}): JSX.Element;
|
||||
declare function OneThing(k: {yxx1: string, children: string}): JSX.Element;
|
||||
declare function OneThing(l: {yy: number, yy1: string}): JSX.Element;
|
||||
declare function OneThing(l: {yy: number, yy1: string, yy2: boolean}): JSX.Element;
|
||||
declare function OneThing(l1: {data: string, "data-prop": boolean}): JSX.Element;
|
||||
|
||||
// OK
|
||||
const c1 = <OneThing yxx='ok' />
|
||||
const c2 = <OneThing yy={100} yy1="hello"/>
|
||||
const c3 = <OneThing yxx="hello" ignore-prop />
|
||||
const c4 = <OneThing data="hello" data-prop />
|
||||
const c5 = <OneThing yxx1='ok'>Hello</OneThing>
|
||||
|
||||
|
||||
declare function TestingOneThing({y1: string}): JSX.Element;
|
||||
~~~~~~
|
||||
!!! error TS2842: 'string' is an unused renaming of 'y1'. Did you intend to use it as a type annotation?
|
||||
!!! related TS2843 tests/cases/conformance/jsx/file.tsx:17:46: We can only write a type for 'y1' by adding a type for the entire parameter here.
|
||||
declare function TestingOneThing(j: {"extra-data": string, yy?: string}): JSX.Element;
|
||||
declare function TestingOneThing(n: {yy: number, direction?: number}): JSX.Element;
|
||||
declare function TestingOneThing(n: {yy: string, name: string}): JSX.Element;
|
||||
|
||||
// OK
|
||||
const d1 = <TestingOneThing y1 extra-data />;
|
||||
const d2 = <TestingOneThing extra-data="hello" />;
|
||||
const d3 = <TestingOneThing extra-data="hello" yy="hihi" />;
|
||||
const d4 = <TestingOneThing extra-data="hello" yy={9} direction={10} />;
|
||||
const d5 = <TestingOneThing extra-data="hello" yy="hello" name="Bob" />;
|
||||
|
||||
|
||||
declare function TestingOptional(a: {y1?: string, y2?: number}): JSX.Element;
|
||||
declare function TestingOptional(a: {y1: boolean, y2?: number, y3: boolean}): JSX.Element;
|
||||
|
||||
// OK
|
||||
const e1 = <TestingOptional />
|
||||
const e3 = <TestingOptional y1="hello"/>
|
||||
const e4 = <TestingOptional y1="hello" y2={1000} />
|
||||
const e5 = <TestingOptional y1 y3/>
|
||||
const e6 = <TestingOptional y1 y3 y2={10} />
|
||||
const e2 = <TestingOptional y1 y3 extra-prop/>
|
||||
|
||||
|
||||
|
||||
@@ -75,27 +75,27 @@ const c5 = <OneThing yxx1='ok'>Hello</OneThing>
|
||||
|
||||
|
||||
declare function TestingOneThing({y1: string}): JSX.Element;
|
||||
>TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; }
|
||||
>TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; }
|
||||
>y1 : any
|
||||
>string : any
|
||||
>JSX : any
|
||||
|
||||
declare function TestingOneThing(j: {"extra-data": string, yy?: string}): JSX.Element;
|
||||
>TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string;}): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; }
|
||||
>TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string;}): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; }
|
||||
>j : { "extra-data": string; yy?: string; }
|
||||
>"extra-data" : string
|
||||
>yy : string
|
||||
>JSX : any
|
||||
|
||||
declare function TestingOneThing(n: {yy: number, direction?: number}): JSX.Element;
|
||||
>TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number;}): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; }
|
||||
>TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number;}): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; }
|
||||
>n : { yy: number; direction?: number; }
|
||||
>yy : number
|
||||
>direction : number
|
||||
>JSX : any
|
||||
|
||||
declare function TestingOneThing(n: {yy: string, name: string}): JSX.Element;
|
||||
>TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string;}): JSX.Element; }
|
||||
>TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string;}): JSX.Element; }
|
||||
>n : { yy: string; name: string; }
|
||||
>yy : string
|
||||
>name : string
|
||||
@@ -105,27 +105,27 @@ declare function TestingOneThing(n: {yy: string, name: string}): JSX.Element;
|
||||
const d1 = <TestingOneThing y1 extra-data />;
|
||||
>d1 : JSX.Element
|
||||
><TestingOneThing y1 extra-data /> : JSX.Element
|
||||
>TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; }
|
||||
>TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; }
|
||||
>y1 : true
|
||||
>extra-data : true
|
||||
|
||||
const d2 = <TestingOneThing extra-data="hello" />;
|
||||
>d2 : JSX.Element
|
||||
><TestingOneThing extra-data="hello" /> : JSX.Element
|
||||
>TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; }
|
||||
>TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; }
|
||||
>extra-data : string
|
||||
|
||||
const d3 = <TestingOneThing extra-data="hello" yy="hihi" />;
|
||||
>d3 : JSX.Element
|
||||
><TestingOneThing extra-data="hello" yy="hihi" /> : JSX.Element
|
||||
>TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; }
|
||||
>TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; }
|
||||
>extra-data : string
|
||||
>yy : string
|
||||
|
||||
const d4 = <TestingOneThing extra-data="hello" yy={9} direction={10} />;
|
||||
>d4 : JSX.Element
|
||||
><TestingOneThing extra-data="hello" yy={9} direction={10} /> : JSX.Element
|
||||
>TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; }
|
||||
>TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; }
|
||||
>extra-data : string
|
||||
>yy : number
|
||||
>9 : 9
|
||||
@@ -135,7 +135,7 @@ const d4 = <TestingOneThing extra-data="hello" yy={9} direction={10} />;
|
||||
const d5 = <TestingOneThing extra-data="hello" yy="hello" name="Bob" />;
|
||||
>d5 : JSX.Element
|
||||
><TestingOneThing extra-data="hello" yy="hello" name="Bob" /> : JSX.Element
|
||||
>TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; }
|
||||
>TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; }
|
||||
>extra-data : string
|
||||
>yy : string
|
||||
>name : string
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
// @target: es2015
|
||||
// @declaration: true
|
||||
// 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"; }
|
||||
@@ -0,0 +1,33 @@
|
||||
// @filename: a.d.ts
|
||||
type O = { a: string; b: number; c: number; };
|
||||
type F1 = (arg: number) => any;
|
||||
type F2 = ({ a: string }: O) => any;
|
||||
type F3 = ({ a: string, b, c }: O) => any;
|
||||
type F4 = ({ a: string }: O) => any;
|
||||
type F5 = ({ a: string, b, c }: O) => any;
|
||||
type F6 = ({ a: string }) => typeof string;
|
||||
type F7 = ({ a: string, b: number }) => typeof number;
|
||||
type F8 = ({ a, b: number }) => typeof number;
|
||||
type F9 = ([a, b, c]) => void;
|
||||
|
||||
type G1 = (arg: number) => any;
|
||||
type G2 = ({ a: string }: O) => any;
|
||||
type G3 = ({ a: string, b, c }: O) => any;
|
||||
type G4 = ({ a: string }: O) => any;
|
||||
type G5 = ({ a: string, b, c }: O) => any;
|
||||
type G6 = ({ a: string }) => typeof string;
|
||||
type G7 = ({ a: string, b: number }) => typeof number;
|
||||
type G8 = ({ a, b: number }) => typeof number;
|
||||
type G9 = ([a, b, c]) => void;
|
||||
|
||||
interface I {
|
||||
method1(arg: number): any;
|
||||
method2({ a: string }): any;
|
||||
|
||||
(arg: number): any;
|
||||
({ a: string }): any;
|
||||
|
||||
new (arg: number): any;
|
||||
new ({ a: string }): any;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// @target: es2015
|
||||
const sym = Symbol();
|
||||
type O = Record<symbol, unknown>
|
||||
type F14 = ({ [sym]: string }: O) => void; // Error
|
||||
type G14 = new ({ [sym]: string }: O) => void; // Error
|
||||
|
||||
const f13 = ({ [sym]: string }: O) => { };
|
||||
function f14 ({ [sym]: string }: O) { };
|
||||
Reference in New Issue
Block a user