Fix issue #16803 do not error on getters/setters (#18031)

This commit is contained in:
Wesley Wigham
2017-08-24 15:53:09 -07:00
committed by GitHub
parent 2f1bd8cff9
commit 336df751ea
9 changed files with 133 additions and 5 deletions

View File

@@ -497,6 +497,8 @@ namespace ts {
const builtinGlobals = createSymbolTable();
builtinGlobals.set(undefinedSymbol.escapedName, undefinedSymbol);
const isNotOverloadAndNotAccessor = and(isNotOverload, isNotAccessor);
initializeTypeChecker();
return checker;
@@ -22257,7 +22259,7 @@ namespace ts {
if (flags & (SymbolFlags.Namespace | SymbolFlags.Interface | SymbolFlags.Enum)) {
return;
}
const exportedDeclarationsCount = countWhere(declarations, isNotOverload);
const exportedDeclarationsCount = countWhere(declarations, isNotOverloadAndNotAccessor);
if (flags & SymbolFlags.TypeAlias && exportedDeclarationsCount <= 2) {
// it is legal to merge type alias with other values
// so count should be either 1 (just type alias) or 2 (type alias + merged value)
@@ -22273,11 +22275,16 @@ namespace ts {
});
links.exportsChecked = true;
}
}
function isNotOverload(declaration: Declaration): boolean {
return (declaration.kind !== SyntaxKind.FunctionDeclaration && declaration.kind !== SyntaxKind.MethodDeclaration) ||
!!(declaration as FunctionDeclaration).body;
}
function isNotAccessor(declaration: Declaration): boolean {
// Accessors check for their own matching duplicates, and in contexts where they are valid, there are already duplicate identifier checks
return !isAccessor(declaration);
}
function isNotOverload(declaration: Declaration): boolean {
return (declaration.kind !== SyntaxKind.FunctionDeclaration && declaration.kind !== SyntaxKind.MethodDeclaration) ||
!!(declaration as FunctionDeclaration).body;
}
function checkSourceElement(node: Node): void {

View File

@@ -2626,4 +2626,8 @@ namespace ts {
export function isCheckJsEnabledForFile(sourceFile: SourceFile, compilerOptions: CompilerOptions) {
return sourceFile.checkJsDirective ? sourceFile.checkJsDirective.enabled : compilerOptions.checkJs;
}
export function and<T>(f: (arg: T) => boolean, g: (arg: T) => boolean) {
return (arg: T) => f(arg) && g(arg);
}
}