@@ -122,8 +122,8 @@ namespace ts {
122122
123123 const noConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
124124
125- const anySignature = createSignature(undefined, undefined, emptyArray, anyType, undefined, 0, false, false);
126- const unknownSignature = createSignature(undefined, undefined, emptyArray, unknownType, undefined, 0, false, false);
125+ const anySignature = createSignature(undefined, undefined, emptyArray, anyType, undefined, 0, /*hasRestParameter*/ false, /*hasStringLiterals*/ false);
126+ const unknownSignature = createSignature(undefined, undefined, emptyArray, unknownType, undefined, 0, /*hasRestParameter*/ false, /*hasStringLiterals*/ false);
127127
128128 const globals: SymbolTable = {};
129129
@@ -200,6 +200,10 @@ namespace ts {
200200 "symbol": {
201201 type: esSymbolType,
202202 flags: TypeFlags.ESSymbol
203+ },
204+ "undefined": {
205+ type: undefinedType,
206+ flags: TypeFlags.ContainsUndefinedOrNull
203207 }
204208 };
205209
@@ -295,7 +299,12 @@ namespace ts {
295299 target.constEnumOnlyModule = false;
296300 }
297301 target.flags |= source.flags;
298- if (!target.valueDeclaration && source.valueDeclaration) target.valueDeclaration = source.valueDeclaration;
302+ if (source.valueDeclaration &&
303+ (!target.valueDeclaration ||
304+ (target.valueDeclaration.kind === SyntaxKind.ModuleDeclaration && source.valueDeclaration.kind !== SyntaxKind.ModuleDeclaration))) {
305+ // other kinds of value declarations take precedence over modules
306+ target.valueDeclaration = source.valueDeclaration;
307+ }
299308 forEach(source.declarations, node => {
300309 target.declarations.push(node);
301310 });
@@ -2267,7 +2276,7 @@ namespace ts {
22672276 return false;
22682277 }
22692278 resolutionTargets.push(target);
2270- resolutionResults.push(true);
2279+ resolutionResults.push(/*items*/ true);
22712280 resolutionPropertyNames.push(propertyName);
22722281 return true;
22732282 }
@@ -3339,7 +3348,7 @@ namespace ts {
33393348
33403349 function getDefaultConstructSignatures(classType: InterfaceType): Signature[] {
33413350 if (!hasClassBaseType(classType)) {
3342- return [createSignature(undefined, classType.localTypeParameters, emptyArray, classType, undefined, 0, false, false)];
3351+ return [createSignature(undefined, classType.localTypeParameters, emptyArray, classType, undefined, 0, /*hasRestParameter*/ false, /*hasStringLiterals*/ false)];
33433352 }
33443353 const baseConstructorType = getBaseConstructorTypeOfClass(classType);
33453354 const baseSignatures = getSignaturesOfType(baseConstructorType, SignatureKind.Construct);
@@ -3820,7 +3829,13 @@ namespace ts {
38203829 let minArgumentCount = -1;
38213830 for (let i = 0, n = declaration.parameters.length; i < n; i++) {
38223831 const param = declaration.parameters[i];
3823- parameters.push(param.symbol);
3832+ let paramSymbol = param.symbol;
3833+ // Include parameter symbol instead of property symbol in the signature
3834+ if (paramSymbol && !!(paramSymbol.flags & SymbolFlags.Property) && !isBindingPattern(param.name)) {
3835+ const resolvedSymbol = resolveName(param, paramSymbol.name, SymbolFlags.Value, undefined, undefined);
3836+ paramSymbol = resolvedSymbol;
3837+ }
3838+ parameters.push(paramSymbol);
38243839 if (param.type && param.type.kind === SyntaxKind.StringLiteral) {
38253840 hasStringLiterals = true;
38263841 }
@@ -3964,7 +3979,7 @@ namespace ts {
39643979 }
39653980
39663981 function getSignatureInstantiation(signature: Signature, typeArguments: Type[]): Signature {
3967- return instantiateSignature(signature, createTypeMapper(signature.typeParameters, typeArguments), true);
3982+ return instantiateSignature(signature, createTypeMapper(signature.typeParameters, typeArguments), /*eraseTypeParameters*/ true);
39683983 }
39693984
39703985 function getErasedSignature(signature: Signature): Signature {
@@ -3974,7 +3989,7 @@ namespace ts {
39743989 signature.erasedSignatureCache = instantiateSignature(getErasedSignature(signature.target), signature.mapper);
39753990 }
39763991 else {
3977- signature.erasedSignatureCache = instantiateSignature(signature, createTypeEraser(signature.typeParameters), true);
3992+ signature.erasedSignatureCache = instantiateSignature(signature, createTypeEraser(signature.typeParameters), /*eraseTypeParameters*/ true);
39783993 }
39793994 }
39803995 return signature.erasedSignatureCache;
@@ -5090,7 +5105,7 @@ namespace ts {
50905105 let result = Ternary.True;
50915106 const sourceTypes = source.types;
50925107 for (const sourceType of sourceTypes) {
5093- const related = typeRelatedToSomeType(sourceType, target, false);
5108+ const related = typeRelatedToSomeType(sourceType, target, /*reportErrors*/ false);
50945109 if (!related) {
50955110 return Ternary.False;
50965111 }
@@ -5488,7 +5503,7 @@ namespace ts {
54885503 const saveErrorInfo = errorInfo;
54895504 let related = isRelatedTo(s, t, reportErrors);
54905505 if (!related) {
5491- related = isRelatedTo(t, s, false);
5506+ related = isRelatedTo(t, s, /*reportErrors*/ false);
54925507 if (!related) {
54935508 if (reportErrors) {
54945509 reportError(Diagnostics.Types_of_parameters_0_and_1_are_incompatible,
@@ -5615,7 +5630,7 @@ namespace ts {
56155630 let related: Ternary;
56165631 if (sourceStringType && sourceNumberType) {
56175632 // If we know for sure we're testing both string and numeric index types then only report errors from the second one
5618- related = isRelatedTo(sourceStringType, targetType, false) || isRelatedTo(sourceNumberType, targetType, reportErrors);
5633+ related = isRelatedTo(sourceStringType, targetType, /*reportErrors*/ false) || isRelatedTo(sourceNumberType, targetType, reportErrors);
56195634 }
56205635 else {
56215636 related = isRelatedTo(sourceStringType || sourceNumberType, targetType, reportErrors);
@@ -6469,6 +6484,10 @@ namespace ts {
64696484 assumeTrue = !assumeTrue;
64706485 }
64716486 const typeInfo = primitiveTypeInfo[right.text];
6487+ // Don't narrow `undefined`
6488+ if (typeInfo && typeInfo.type === undefinedType) {
6489+ return type;
6490+ }
64726491 // If the type to be narrowed is any and we're checking a primitive with assumeTrue=true, return the primitive
64736492 if (!!(type.flags & TypeFlags.Any) && typeInfo && assumeTrue) {
64746493 return typeInfo.type;
@@ -9859,7 +9878,7 @@ namespace ts {
98599878 return type;
98609879 }
98619880
9862- function checkFunctionExpressionOrObjectLiteralMethodBody(node: FunctionExpression | MethodDeclaration) {
9881+ function checkFunctionExpressionOrObjectLiteralMethodBody(node: ArrowFunction | FunctionExpression | MethodDeclaration) {
98639882 Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node));
98649883
98659884 const isAsync = isAsyncFunctionLike(node);
@@ -11346,11 +11365,17 @@ namespace ts {
1134611365 const errorNode: Node = (<FunctionLikeDeclaration>subsequentNode).name || subsequentNode;
1134711366 // TODO(jfreeman): These are methods, so handle computed name case
1134811367 if (node.name && (<FunctionLikeDeclaration>subsequentNode).name && (<Identifier>node.name).text === (<Identifier>(<FunctionLikeDeclaration>subsequentNode).name).text) {
11349- // the only situation when this is possible (same kind\same name but different symbol) - mixed static and instance class members
11350- Debug.assert(node.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature);
11351- Debug.assert((node.flags & NodeFlags.Static) !== (subsequentNode.flags & NodeFlags.Static));
11352- const diagnostic = node.flags & NodeFlags.Static ? Diagnostics.Function_overload_must_be_static : Diagnostics.Function_overload_must_not_be_static;
11353- error(errorNode, diagnostic);
11368+ const reportError =
11369+ (node.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature) &&
11370+ (node.flags & NodeFlags.Static) !== (subsequentNode.flags & NodeFlags.Static);
11371+ // we can get here in two cases
11372+ // 1. mixed static and instance class members
11373+ // 2. something with the same name was defined before the set of overloads that prevents them from merging
11374+ // here we'll report error only for the first case since for second we should already report error in binder
11375+ if (reportError) {
11376+ const diagnostic = node.flags & NodeFlags.Static ? Diagnostics.Function_overload_must_be_static : Diagnostics.Function_overload_must_not_be_static;
11377+ error(errorNode, diagnostic);
11378+ }
1135411379 return;
1135511380 }
1135611381 else if (nodeIsPresent((<FunctionLikeDeclaration>subsequentNode).body)) {
@@ -12885,13 +12910,13 @@ namespace ts {
1288512910 // In a 'switch' statement, each 'case' expression must be of a type that is assignable to or from the type of the 'switch' expression.
1288612911 const caseType = checkExpression(caseClause.expression);
1288712912
12888- // Permit 'number[] | "foo"' to be asserted to 'string'.
12889- if (expressionTypeIsStringLike && someConstituentTypeHasKind(caseType, TypeFlags.StringLike)) {
12890- return;
12891- }
12913+ const expressionTypeIsAssignableToCaseType =
12914+ // Permit 'number[] | "foo"' to be asserted to 'string'.
12915+ (expressionTypeIsStringLike && someConstituentTypeHasKind(caseType, TypeFlags.StringLike)) ||
12916+ isTypeAssignableTo(expressionType, caseType);
1289212917
12893- if (!isTypeAssignableTo(expressionType, caseType) ) {
12894- // check 'expressionType isAssignableTo caseType' failed , try the reversed check and report errors if it fails
12918+ if (!expressionTypeIsAssignableToCaseType ) {
12919+ // 'expressionType is not assignable to caseType', try the reversed check and report errors if it fails
1289512920 checkTypeAssignableTo(caseType, expressionType, caseClause.expression, /*headMessage*/ undefined);
1289612921 }
1289712922 }
0 commit comments