mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-11 10:00:13 -06:00
Do not report error on implicityly any binding element if it is from parameter destructuring of private method
Fixes #8002
This commit is contained in:
parent
9d35468d17
commit
b24883304b
@ -2843,7 +2843,7 @@ namespace ts {
|
||||
if (isBindingPattern(element.name)) {
|
||||
return getTypeFromBindingPattern(<BindingPattern>element.name, includePatternInType);
|
||||
}
|
||||
if (compilerOptions.noImplicitAny) {
|
||||
if (compilerOptions.noImplicitAny && canReportImplicitAnyError(element)) {
|
||||
reportImplicitAnyError(element, anyType);
|
||||
}
|
||||
return anyType;
|
||||
@ -2936,14 +2936,18 @@ namespace ts {
|
||||
|
||||
// Report implicit any errors unless this is a private property within an ambient declaration
|
||||
if (reportErrors && compilerOptions.noImplicitAny) {
|
||||
const root = getRootDeclaration(declaration);
|
||||
if (!isPrivateWithinAmbient(root) && !(root.kind === SyntaxKind.Parameter && isPrivateWithinAmbient(root.parent))) {
|
||||
if (canReportImplicitAnyError(declaration)) {
|
||||
reportImplicitAnyError(declaration, type);
|
||||
}
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
function canReportImplicitAnyError(declaration: VariableLikeDeclaration) {
|
||||
const root = getRootDeclaration(declaration);
|
||||
return !isPrivateWithinAmbient(root) && !(root.kind === SyntaxKind.Parameter && isPrivateWithinAmbient(root.parent));
|
||||
}
|
||||
|
||||
function getTypeOfVariableOrParameterOrProperty(symbol: Symbol): Type {
|
||||
const links = getSymbolLinks(symbol);
|
||||
if (!links.type) {
|
||||
|
||||
@ -1,17 +0,0 @@
|
||||
tests/cases/compiler/noImplicitAnyDestructuringInPrivateMethod.ts(10,19): error TS7031: Binding element 'a' implicitly has an 'any' type.
|
||||
|
||||
|
||||
==== tests/cases/compiler/noImplicitAnyDestructuringInPrivateMethod.ts (1 errors) ====
|
||||
type Arg = {
|
||||
a: number;
|
||||
};
|
||||
export class Bar {
|
||||
private bar({ a, }: Arg): number {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
export declare class Bar2 {
|
||||
private bar({ a, });
|
||||
~
|
||||
!!! error TS7031: Binding element 'a' implicitly has an 'any' type.
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
=== tests/cases/compiler/noImplicitAnyDestructuringInPrivateMethod.ts ===
|
||||
type Arg = {
|
||||
>Arg : Symbol(Arg, Decl(noImplicitAnyDestructuringInPrivateMethod.ts, 0, 0))
|
||||
|
||||
a: number;
|
||||
>a : Symbol(a, Decl(noImplicitAnyDestructuringInPrivateMethod.ts, 0, 12))
|
||||
|
||||
};
|
||||
export class Bar {
|
||||
>Bar : Symbol(Bar, Decl(noImplicitAnyDestructuringInPrivateMethod.ts, 2, 2))
|
||||
|
||||
private bar({ a, }: Arg): number {
|
||||
>bar : Symbol(Bar.bar, Decl(noImplicitAnyDestructuringInPrivateMethod.ts, 3, 18))
|
||||
>a : Symbol(a, Decl(noImplicitAnyDestructuringInPrivateMethod.ts, 4, 17))
|
||||
>Arg : Symbol(Arg, Decl(noImplicitAnyDestructuringInPrivateMethod.ts, 0, 0))
|
||||
|
||||
return a;
|
||||
>a : Symbol(a, Decl(noImplicitAnyDestructuringInPrivateMethod.ts, 4, 17))
|
||||
}
|
||||
}
|
||||
export declare class Bar2 {
|
||||
>Bar2 : Symbol(Bar2, Decl(noImplicitAnyDestructuringInPrivateMethod.ts, 7, 1))
|
||||
|
||||
private bar({ a, });
|
||||
>bar : Symbol(Bar2.bar, Decl(noImplicitAnyDestructuringInPrivateMethod.ts, 8, 27))
|
||||
>a : Symbol(a, Decl(noImplicitAnyDestructuringInPrivateMethod.ts, 9, 17))
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
=== tests/cases/compiler/noImplicitAnyDestructuringInPrivateMethod.ts ===
|
||||
type Arg = {
|
||||
>Arg : { a: number; }
|
||||
|
||||
a: number;
|
||||
>a : number
|
||||
|
||||
};
|
||||
export class Bar {
|
||||
>Bar : Bar
|
||||
|
||||
private bar({ a, }: Arg): number {
|
||||
>bar : ({a}: { a: number; }) => number
|
||||
>a : number
|
||||
>Arg : { a: number; }
|
||||
|
||||
return a;
|
||||
>a : number
|
||||
}
|
||||
}
|
||||
export declare class Bar2 {
|
||||
>Bar2 : Bar2
|
||||
|
||||
private bar({ a, });
|
||||
>bar : ({a}: { a: any; }) => any
|
||||
>a : any
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user