mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-18 07:29:16 -05:00
Merge branch 'master' into report-multiple-overload-errors
This commit is contained in:
@@ -7234,8 +7234,8 @@ namespace ts {
|
||||
function resolveIntersectionTypeMembers(type: IntersectionType) {
|
||||
// The members and properties collections are empty for intersection types. To get all properties of an
|
||||
// intersection type use getPropertiesOfType (only the language service uses this).
|
||||
let callSignatures: ReadonlyArray<Signature> = emptyArray;
|
||||
let constructSignatures: ReadonlyArray<Signature> = emptyArray;
|
||||
let callSignatures: Signature[] | undefined;
|
||||
let constructSignatures: Signature[] | undefined;
|
||||
let stringIndexInfo: IndexInfo | undefined;
|
||||
let numberIndexInfo: IndexInfo | undefined;
|
||||
const types = type.types;
|
||||
@@ -7257,13 +7257,22 @@ namespace ts {
|
||||
return clone;
|
||||
});
|
||||
}
|
||||
constructSignatures = concatenate(constructSignatures, signatures);
|
||||
constructSignatures = appendSignatures(constructSignatures, signatures);
|
||||
}
|
||||
callSignatures = concatenate(callSignatures, getSignaturesOfType(t, SignatureKind.Call));
|
||||
callSignatures = appendSignatures(callSignatures, getSignaturesOfType(t, SignatureKind.Call));
|
||||
stringIndexInfo = intersectIndexInfos(stringIndexInfo, getIndexInfoOfType(t, IndexKind.String));
|
||||
numberIndexInfo = intersectIndexInfos(numberIndexInfo, getIndexInfoOfType(t, IndexKind.Number));
|
||||
}
|
||||
setStructuredTypeMembers(type, emptySymbols, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo);
|
||||
setStructuredTypeMembers(type, emptySymbols, callSignatures || emptyArray, constructSignatures || emptyArray, stringIndexInfo, numberIndexInfo);
|
||||
}
|
||||
|
||||
function appendSignatures(signatures: Signature[] | undefined, newSignatures: readonly Signature[]) {
|
||||
for (const sig of newSignatures) {
|
||||
if (!signatures || every(signatures, s => !compareSignaturesIdentical(s, sig, /*partialMatch*/ false, /*ignoreThisTypes*/ false, /*ignoreReturnTypes*/ false, compareTypesIdentical))) {
|
||||
signatures = append(signatures, sig);
|
||||
}
|
||||
}
|
||||
return signatures;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -14403,20 +14412,25 @@ namespace ts {
|
||||
if (!(isMatchingSignature(source, target, partialMatch))) {
|
||||
return Ternary.False;
|
||||
}
|
||||
// Check that the two signatures have the same number of type parameters. We might consider
|
||||
// also checking that any type parameter constraints match, but that would require instantiating
|
||||
// the constraints with a common set of type arguments to get relatable entities in places where
|
||||
// type parameters occur in the constraints. The complexity of doing that doesn't seem worthwhile,
|
||||
// particularly as we're comparing erased versions of the signatures below.
|
||||
// Check that the two signatures have the same number of type parameters.
|
||||
if (length(source.typeParameters) !== length(target.typeParameters)) {
|
||||
return Ternary.False;
|
||||
}
|
||||
// Spec 1.0 Section 3.8.3 & 3.8.4:
|
||||
// M and N (the signatures) are instantiated using type Any as the type argument for all type parameters declared by M and N
|
||||
source = getErasedSignature(source);
|
||||
target = getErasedSignature(target);
|
||||
// Check that type parameter constraints and defaults match. If they do, instantiate the source
|
||||
// signature with the type parameters of the target signature and continue the comparison.
|
||||
if (target.typeParameters) {
|
||||
const mapper = createTypeMapper(source.typeParameters!, target.typeParameters);
|
||||
for (let i = 0; i < target.typeParameters.length; i++) {
|
||||
const s = source.typeParameters![i];
|
||||
const t = target.typeParameters[i];
|
||||
if (!(s === t || compareTypes(instantiateType(getConstraintFromTypeParameter(s), mapper) || unknownType, getConstraintFromTypeParameter(t) || unknownType) &&
|
||||
compareTypes(instantiateType(getDefaultFromTypeParameter(s), mapper) || unknownType, getDefaultFromTypeParameter(t) || unknownType))) {
|
||||
return Ternary.False;
|
||||
}
|
||||
}
|
||||
source = instantiateSignature(source, mapper, /*eraseTypeParameters*/ true);
|
||||
}
|
||||
let result = Ternary.True;
|
||||
|
||||
if (!ignoreThisTypes) {
|
||||
const sourceThisType = getThisTypeOfSignature(source);
|
||||
if (sourceThisType) {
|
||||
@@ -14430,7 +14444,6 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const targetLen = getParameterCount(target);
|
||||
for (let i = 0; i < targetLen; i++) {
|
||||
const s = getTypeAtPosition(source, i);
|
||||
|
||||
@@ -245,6 +245,7 @@ namespace ts {
|
||||
esnext: ModuleKind.ESNext
|
||||
}),
|
||||
affectsModuleResolution: true,
|
||||
affectsEmit: true,
|
||||
paramType: Diagnostics.KIND,
|
||||
showInSimplifiedHelpView: true,
|
||||
category: Diagnostics.Basic_Options,
|
||||
@@ -590,6 +591,7 @@ namespace ts {
|
||||
name: "esModuleInterop",
|
||||
type: "boolean",
|
||||
affectsSemanticDiagnostics: true,
|
||||
affectsEmit: true,
|
||||
showInSimplifiedHelpView: true,
|
||||
category: Diagnostics.Module_Resolution_Options,
|
||||
description: Diagnostics.Enables_emit_interoperability_between_CommonJS_and_ES_Modules_via_creation_of_namespace_objects_for_all_imports_Implies_allowSyntheticDefaultImports
|
||||
|
||||
@@ -2201,13 +2201,13 @@ namespace ts {
|
||||
let result: (JSDoc | JSDocTag)[] | undefined;
|
||||
// Pull parameter comments from declaring function as well
|
||||
if (isVariableLike(hostNode) && hasInitializer(hostNode) && hasJSDocNodes(hostNode.initializer!)) {
|
||||
result = addRange(result, (hostNode.initializer as HasJSDoc).jsDoc!);
|
||||
result = append(result, last((hostNode.initializer as HasJSDoc).jsDoc!));
|
||||
}
|
||||
|
||||
let node: Node | undefined = hostNode;
|
||||
while (node && node.parent) {
|
||||
if (hasJSDocNodes(node)) {
|
||||
result = addRange(result, node.jsDoc!);
|
||||
result = append(result, last(node.jsDoc!));
|
||||
}
|
||||
|
||||
if (node.kind === SyntaxKind.Parameter) {
|
||||
|
||||
@@ -608,7 +608,6 @@ namespace ts {
|
||||
/*@internal*/
|
||||
getCurrentProgram(): T;
|
||||
/** Closes the watch */
|
||||
/*@internal*/
|
||||
close(): void;
|
||||
}
|
||||
|
||||
|
||||
@@ -906,7 +906,7 @@ class someClass { }`),
|
||||
"target": "esnext",
|
||||
}
|
||||
}`);
|
||||
},
|
||||
},
|
||||
expectedDiagnostics: [
|
||||
getExpectedDiagnosticForProjectsInBuild("src/core/tsconfig.json"),
|
||||
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/core/tsconfig.json", "src/core/anotherModule.js"],
|
||||
@@ -931,6 +931,94 @@ class someClass { }`),
|
||||
baselineOnly: true,
|
||||
verifyDiagnostics: true
|
||||
});
|
||||
|
||||
verifyTsbuildOutput({
|
||||
scenario: "when module option changes",
|
||||
projFs: () => projFs,
|
||||
time,
|
||||
tick,
|
||||
proj: "sample1",
|
||||
rootNames: ["/src/core"],
|
||||
expectedMapFileNames: emptyArray,
|
||||
lastProjectOutputJs: "/src/core/index.js",
|
||||
initialBuild: {
|
||||
modifyFs: fs => fs.writeFileSync("/src/core/tsconfig.json", `{
|
||||
"compilerOptions": {
|
||||
"incremental": true,
|
||||
"module": "commonjs"
|
||||
}
|
||||
}`),
|
||||
expectedDiagnostics: [
|
||||
getExpectedDiagnosticForProjectsInBuild("src/core/tsconfig.json"),
|
||||
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/core/tsconfig.json", "src/core/anotherModule.js"],
|
||||
[Diagnostics.Building_project_0, "/src/core/tsconfig.json"],
|
||||
]
|
||||
},
|
||||
incrementalDtsChangedBuild: {
|
||||
modifyFs: fs => replaceText(fs, "/src/core/tsconfig.json", `"module": "commonjs"`, `"module": "amd"`),
|
||||
expectedDiagnostics: [
|
||||
getExpectedDiagnosticForProjectsInBuild("src/core/tsconfig.json"),
|
||||
[Diagnostics.Project_0_is_out_of_date_because_oldest_output_1_is_older_than_newest_input_2, "src/core/tsconfig.json", "src/core/anotherModule.js", "src/core/tsconfig.json"],
|
||||
[Diagnostics.Building_project_0, "/src/core/tsconfig.json"]
|
||||
]
|
||||
},
|
||||
outputFiles: [
|
||||
"/src/core/anotherModule.js",
|
||||
"/src/core/index.js",
|
||||
"/src/core/tsconfig.tsbuildinfo",
|
||||
],
|
||||
baselineOnly: true,
|
||||
verifyDiagnostics: true
|
||||
});
|
||||
|
||||
verifyTsbuildOutput({
|
||||
scenario: "when esModuleInterop option changes",
|
||||
projFs: () => projFs,
|
||||
time,
|
||||
tick,
|
||||
proj: "sample1",
|
||||
rootNames: ["/src/tests"],
|
||||
expectedMapFileNames: emptyArray,
|
||||
lastProjectOutputJs: "/src/tests/index.js",
|
||||
initialBuild: {
|
||||
modifyFs: fs => fs.writeFileSync("/src/tests/tsconfig.json", `{
|
||||
"references": [
|
||||
{ "path": "../core" },
|
||||
{ "path": "../logic" }
|
||||
],
|
||||
"files": ["index.ts"],
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"declaration": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"skipDefaultLibCheck": true,
|
||||
"esModuleInterop": false
|
||||
}
|
||||
}`),
|
||||
expectedDiagnostics: [
|
||||
getExpectedDiagnosticForProjectsInBuild("src/core/tsconfig.json", "src/logic/tsconfig.json", "src/tests/tsconfig.json"),
|
||||
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/core/tsconfig.json", "src/core/anotherModule.js"],
|
||||
[Diagnostics.Building_project_0, "/src/core/tsconfig.json"],
|
||||
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/logic/tsconfig.json", "src/logic/index.js"],
|
||||
[Diagnostics.Building_project_0, "/src/logic/tsconfig.json"],
|
||||
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/tests/tsconfig.json", "src/tests/index.js"],
|
||||
[Diagnostics.Building_project_0, "/src/tests/tsconfig.json"]
|
||||
]
|
||||
},
|
||||
incrementalDtsChangedBuild: {
|
||||
modifyFs: fs => replaceText(fs, "/src/tests/tsconfig.json", `"esModuleInterop": false`, `"esModuleInterop": true`),
|
||||
expectedDiagnostics: [
|
||||
getExpectedDiagnosticForProjectsInBuild("src/core/tsconfig.json", "src/logic/tsconfig.json", "src/tests/tsconfig.json"),
|
||||
[Diagnostics.Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2, "src/core/tsconfig.json", "src/core/anotherModule.ts", "src/core/anotherModule.js"],
|
||||
[Diagnostics.Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2, "src/logic/tsconfig.json", "src/logic/index.ts", "src/logic/index.js"],
|
||||
[Diagnostics.Project_0_is_out_of_date_because_oldest_output_1_is_older_than_newest_input_2, "src/tests/tsconfig.json", "src/tests/index.js", "src/tests/tsconfig.json"],
|
||||
[Diagnostics.Building_project_0, "/src/tests/tsconfig.json"]
|
||||
]
|
||||
},
|
||||
outputFiles: [],
|
||||
baselineOnly: true,
|
||||
verifyDiagnostics: true
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user