mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-11 10:00:13 -06:00
Merge pull request #8018 from Microsoft/privateImplicitBindingAny
Do not report error on implicityly any binding element if it is from parameter destructuring of private method
This commit is contained in:
commit
146e99425b
@ -2843,7 +2843,7 @@ namespace ts {
|
||||
if (isBindingPattern(element.name)) {
|
||||
return getTypeFromBindingPattern(<BindingPattern>element.name, includePatternInType);
|
||||
}
|
||||
if (compilerOptions.noImplicitAny) {
|
||||
if (compilerOptions.noImplicitAny && !declarationBelongsToPrivateAmbientMember(element)) {
|
||||
reportImplicitAnyError(element, anyType);
|
||||
}
|
||||
return anyType;
|
||||
@ -2936,14 +2936,19 @@ 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 (!declarationBelongsToPrivateAmbientMember(declaration)) {
|
||||
reportImplicitAnyError(declaration, type);
|
||||
}
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
function declarationBelongsToPrivateAmbientMember(declaration: VariableLikeDeclaration) {
|
||||
const root = getRootDeclaration(declaration);
|
||||
const memberDeclaration = root.kind === SyntaxKind.Parameter ? root.parent : root;
|
||||
return isPrivateWithinAmbient(memberDeclaration);
|
||||
}
|
||||
|
||||
function getTypeOfVariableOrParameterOrProperty(symbol: Symbol): Type {
|
||||
const links = getSymbolLinks(symbol);
|
||||
if (!links.type) {
|
||||
|
||||
@ -0,0 +1,34 @@
|
||||
//// [noImplicitAnyDestructuringInPrivateMethod.ts]
|
||||
type Arg = {
|
||||
a: number;
|
||||
};
|
||||
export class Bar {
|
||||
private bar({ a, }: Arg): number {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
export declare class Bar2 {
|
||||
private bar({ a, });
|
||||
}
|
||||
|
||||
//// [noImplicitAnyDestructuringInPrivateMethod.js]
|
||||
"use strict";
|
||||
var Bar = (function () {
|
||||
function Bar() {
|
||||
}
|
||||
Bar.prototype.bar = function (_a) {
|
||||
var a = _a.a;
|
||||
return a;
|
||||
};
|
||||
return Bar;
|
||||
}());
|
||||
exports.Bar = Bar;
|
||||
|
||||
|
||||
//// [noImplicitAnyDestructuringInPrivateMethod.d.ts]
|
||||
export declare class Bar {
|
||||
private bar({a});
|
||||
}
|
||||
export declare class Bar2 {
|
||||
private bar({a});
|
||||
}
|
||||
@ -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
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
// @noimplicitany: true
|
||||
// @declaration: true
|
||||
type Arg = {
|
||||
a: number;
|
||||
};
|
||||
export class Bar {
|
||||
private bar({ a, }: Arg): number {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
export declare class Bar2 {
|
||||
private bar({ a, });
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user