@@ -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);
@@ -3964,7 +3973,7 @@ namespace ts {
39643973 }
39653974
39663975 function getSignatureInstantiation(signature: Signature, typeArguments: Type[]): Signature {
3967- return instantiateSignature(signature, createTypeMapper(signature.typeParameters, typeArguments), true);
3976+ return instantiateSignature(signature, createTypeMapper(signature.typeParameters, typeArguments), /*eraseTypeParameters*/ true);
39683977 }
39693978
39703979 function getErasedSignature(signature: Signature): Signature {
@@ -3974,7 +3983,7 @@ namespace ts {
39743983 signature.erasedSignatureCache = instantiateSignature(getErasedSignature(signature.target), signature.mapper);
39753984 }
39763985 else {
3977- signature.erasedSignatureCache = instantiateSignature(signature, createTypeEraser(signature.typeParameters), true);
3986+ signature.erasedSignatureCache = instantiateSignature(signature, createTypeEraser(signature.typeParameters), /*eraseTypeParameters*/ true);
39783987 }
39793988 }
39803989 return signature.erasedSignatureCache;
@@ -5090,7 +5099,7 @@ namespace ts {
50905099 let result = Ternary.True;
50915100 const sourceTypes = source.types;
50925101 for (const sourceType of sourceTypes) {
5093- const related = typeRelatedToSomeType(sourceType, target, false);
5102+ const related = typeRelatedToSomeType(sourceType, target, /*reportErrors*/ false);
50945103 if (!related) {
50955104 return Ternary.False;
50965105 }
@@ -5488,7 +5497,7 @@ namespace ts {
54885497 const saveErrorInfo = errorInfo;
54895498 let related = isRelatedTo(s, t, reportErrors);
54905499 if (!related) {
5491- related = isRelatedTo(t, s, false);
5500+ related = isRelatedTo(t, s, /*reportErrors*/ false);
54925501 if (!related) {
54935502 if (reportErrors) {
54945503 reportError(Diagnostics.Types_of_parameters_0_and_1_are_incompatible,
@@ -5615,7 +5624,7 @@ namespace ts {
56155624 let related: Ternary;
56165625 if (sourceStringType && sourceNumberType) {
56175626 // 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);
5627+ related = isRelatedTo(sourceStringType, targetType, /*reportErrors*/ false) || isRelatedTo(sourceNumberType, targetType, reportErrors);
56195628 }
56205629 else {
56215630 related = isRelatedTo(sourceStringType || sourceNumberType, targetType, reportErrors);
@@ -6470,6 +6479,10 @@ namespace ts {
64706479 assumeTrue = !assumeTrue;
64716480 }
64726481 const typeInfo = primitiveTypeInfo[right.text];
6482+ // Don't narrow `undefined`
6483+ if (typeInfo && typeInfo.type === undefinedType) {
6484+ return type;
6485+ }
64736486 // If the type to be narrowed is any and we're checking a primitive with assumeTrue=true, return the primitive
64746487 if (!!(type.flags & TypeFlags.Any) && typeInfo && assumeTrue) {
64756488 return typeInfo.type;
@@ -11348,11 +11361,17 @@ namespace ts {
1134811361 const errorNode: Node = (<FunctionLikeDeclaration>subsequentNode).name || subsequentNode;
1134911362 // TODO(jfreeman): These are methods, so handle computed name case
1135011363 if (node.name && (<FunctionLikeDeclaration>subsequentNode).name && (<Identifier>node.name).text === (<Identifier>(<FunctionLikeDeclaration>subsequentNode).name).text) {
11351- // the only situation when this is possible (same kind\same name but different symbol) - mixed static and instance class members
11352- Debug.assert(node.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature);
11353- Debug.assert((node.flags & NodeFlags.Static) !== (subsequentNode.flags & NodeFlags.Static));
11354- const diagnostic = node.flags & NodeFlags.Static ? Diagnostics.Function_overload_must_be_static : Diagnostics.Function_overload_must_not_be_static;
11355- error(errorNode, diagnostic);
11364+ const reportError =
11365+ (node.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature) &&
11366+ (node.flags & NodeFlags.Static) !== (subsequentNode.flags & NodeFlags.Static);
11367+ // we can get here in two cases
11368+ // 1. mixed static and instance class members
11369+ // 2. something with the same name was defined before the set of overloads that prevents them from merging
11370+ // here we'll report error only for the first case since for second we should already report error in binder
11371+ if (reportError) {
11372+ const diagnostic = node.flags & NodeFlags.Static ? Diagnostics.Function_overload_must_be_static : Diagnostics.Function_overload_must_not_be_static;
11373+ error(errorNode, diagnostic);
11374+ }
1135611375 return;
1135711376 }
1135811377 else if (nodeIsPresent((<FunctionLikeDeclaration>subsequentNode).body)) {
0 commit comments