diff --git a/tsc/internal/checker/checker.go b/tsc/internal/checker/checker.go index 10ddb3c0c88b4..e532bd39a29df 100644 --- a/tsc/internal/checker/checker.go +++ b/tsc/internal/checker/checker.go @@ -7511,7 +7511,7 @@ func (c *Checker) isUnreferencedTypeParameter(typeParameter *ast.Node) bool { func (c *Checker) checkUnusedRenamedBindingElements() { for _, node := range c.renamedBindingElementsInTypes { - if c.symbolReferenceLinks.Get(c.getSymbolOfDeclaration(node)).referenceKinds == 0 { + if c.symbolReferenceLinks.Get(c.getSymbolOfDeclaration(node)).referenceKinds&ast.SymbolFlagsVariable == 0 { wrappingDeclaration := ast.WalkUpBindingElementsAndPatterns(node) debug.Assert(ast.IsPartOfParameterDeclaration(wrappingDeclaration), "Only parameter declaration should be checked here") diagnostic := NewDiagnosticForNode(node.Name(), diagnostics.X_0_is_an_unused_renaming_of_1_Did_you_intend_to_use_it_as_a_type_annotation, scanner.DeclarationNameToString(node.Name()), scanner.DeclarationNameToString(node.PropertyName())) diff --git a/tsc/testdata/baselines/reference/compiler/renamingDestructuredPropertyInFunctionType4.errors.txt b/tsc/testdata/baselines/reference/compiler/renamingDestructuredPropertyInFunctionType4.errors.txt new file mode 100644 index 0000000000000..6dd20684e259f --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/renamingDestructuredPropertyInFunctionType4.errors.txt @@ -0,0 +1,30 @@ +renamingDestructuredPropertyInFunctionType4.ts(1,19): error TS2842: 'A' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +renamingDestructuredPropertyInFunctionType4.ts(2,16): error TS2842: 'A' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +renamingDestructuredPropertyInFunctionType4.ts(4,20): error TS2842: 'A' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +renamingDestructuredPropertyInFunctionType4.ts(6,20): error TS2842: 'A' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +renamingDestructuredPropertyInFunctionType4.ts(8,24): error TS2842: 'A' is an unused renaming of 'a'. Did you intend to use it as a type annotation? + + +==== renamingDestructuredPropertyInFunctionType4.ts (5 errors) ==== + const f0: ({a: A}: {a: A}) => void = () => {}; + ~ +!!! error TS2842: 'A' is an unused renaming of 'a'. Did you intend to use it as a type annotation? + const f1: ({a: A}: {a: number}) => void = () => {}; + ~ +!!! error TS2842: 'A' is an unused renaming of 'a'. Did you intend to use it as a type annotation? + + type F1 = ({ a: A }: { a: A }) => A; + ~ +!!! error TS2842: 'A' is an unused renaming of 'a'. Did you intend to use it as a type annotation? + type F2 = ({ a: A }: { a: A }) => typeof A; + type F3 = ({ a: A }: { a: A }) => (value: A) => A; + ~ +!!! error TS2842: 'A' is an unused renaming of 'a'. Did you intend to use it as a type annotation? + type F4 = ({ a: A }: { a: A }) => (value: A) => typeof A; + type F5 = new ({ a: A }: { a: A }) => A; + ~ +!!! error TS2842: 'A' is an unused renaming of 'a'. Did you intend to use it as a type annotation? + + function f2({ a: A }: { a: A }) { return A; } + function f3({ a: A }: { a: A }): A { return null!; } + \ No newline at end of file diff --git a/tsc/testdata/tests/cases/compiler/renamingDestructuredPropertyInFunctionType4.ts b/tsc/testdata/tests/cases/compiler/renamingDestructuredPropertyInFunctionType4.ts new file mode 100644 index 0000000000000..005f81f430436 --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/renamingDestructuredPropertyInFunctionType4.ts @@ -0,0 +1,13 @@ +// @noEmit: true +// @noTypesAndSymbols: true +const f0: ({a: A}: {a: A}) => void = () => {}; +const f1: ({a: A}: {a: number}) => void = () => {}; + +type F1 = ({ a: A }: { a: A }) => A; +type F2 = ({ a: A }: { a: A }) => typeof A; +type F3 = ({ a: A }: { a: A }) => (value: A) => A; +type F4 = ({ a: A }: { a: A }) => (value: A) => typeof A; +type F5 = new ({ a: A }: { a: A }) => A; + +function f2({ a: A }: { a: A }) { return A; } +function f3({ a: A }: { a: A }): A { return null!; }