Skip to content

Commit b27d4bf

Browse files
authored
noop in setTypeAcquisiton for undefined (#41291)
* noop in setTypeAcquisiton for undefined * accept new baseline * add regression test
1 parent 6bde4b5 commit b27d4bf

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

src/server/project.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -706,10 +706,10 @@ namespace ts.server {
706706
return this.projectName;
707707
}
708708

709-
protected removeLocalTypingsFromTypeAcquisition(newTypeAcquisition: TypeAcquisition | undefined): TypeAcquisition {
709+
protected removeLocalTypingsFromTypeAcquisition(newTypeAcquisition: TypeAcquisition): TypeAcquisition {
710710
if (!newTypeAcquisition || !newTypeAcquisition.include) {
711711
// Nothing to filter out, so just return as-is
712-
return newTypeAcquisition || {};
712+
return newTypeAcquisition;
713713
}
714714
return { ...newTypeAcquisition, include: this.removeExistingTypings(newTypeAcquisition.include) };
715715
}
@@ -1410,7 +1410,9 @@ namespace ts.server {
14101410
}
14111411

14121412
setTypeAcquisition(newTypeAcquisition: TypeAcquisition | undefined): void {
1413-
this.typeAcquisition = this.removeLocalTypingsFromTypeAcquisition(newTypeAcquisition);
1413+
if (newTypeAcquisition) {
1414+
this.typeAcquisition = this.removeLocalTypingsFromTypeAcquisition(newTypeAcquisition);
1415+
}
14141416
}
14151417

14161418
getTypeAcquisition() {

src/testRunner/unittests/tsserver/inferredProjects.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,5 +429,26 @@ namespace ts.projectSystem {
429429
configuredRemoved.clear();
430430
}
431431
});
432+
433+
it("regression test - should infer typeAcquisition for inferred projects when set undefined", () => {
434+
const file1 = { path: "/a/file1.js", content: "" };
435+
const host = createServerHost([file1]);
436+
437+
const projectService = createProjectService(host);
438+
439+
projectService.openClientFile(file1.path);
440+
441+
checkNumberOfProjects(projectService, { inferredProjects: 1 });
442+
const inferredProject = projectService.inferredProjects[0];
443+
checkProjectActualFiles(inferredProject, [file1.path]);
444+
inferredProject.setTypeAcquisition(undefined);
445+
446+
const expected = {
447+
enable: true,
448+
include: [],
449+
exclude: []
450+
};
451+
assert.deepEqual(inferredProject.getTypeAcquisition(), expected, "typeAcquisition should be inferred for inferred projects");
452+
});
432453
});
433454
}

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9307,7 +9307,7 @@ declare namespace ts.server {
93079307
enableLanguageService(): void;
93089308
disableLanguageService(lastFileExceededProgramSize?: string): void;
93099309
getProjectName(): string;
9310-
protected removeLocalTypingsFromTypeAcquisition(newTypeAcquisition: TypeAcquisition | undefined): TypeAcquisition;
9310+
protected removeLocalTypingsFromTypeAcquisition(newTypeAcquisition: TypeAcquisition): TypeAcquisition;
93119311
getExternalFiles(): SortedReadonlyArray<string>;
93129312
getSourceFile(path: Path): SourceFile | undefined;
93139313
close(): void;

0 commit comments

Comments
 (0)