Skip to content

Commit d458e30

Browse files
authored
Rewrite getPropFromRaw slightly to surface T in the parameters (#53301)
1 parent 716b592 commit d458e30

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/compiler/commandLineParser.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import {
2929
emptyArray,
3030
endsWith,
3131
ensureTrailingDirectorySeparator,
32-
every,
3332
Expression,
3433
extend,
3534
Extension,
@@ -2974,7 +2973,7 @@ function parseJsonConfigFileContentWorker(
29742973
};
29752974

29762975
function getConfigFileSpecs(): ConfigFileSpecs {
2977-
const referencesOfRaw = getPropFromRaw<ProjectReference>("references", element => typeof element === "object", "object");
2976+
const referencesOfRaw = getPropFromRaw("references", (element): element is ProjectReference => !!element && typeof element === "object", "object");
29782977
const filesSpecs = toPropValue(getSpecsFromRaw("files"));
29792978
if (filesSpecs) {
29802979
const hasZeroOrNoReferences = referencesOfRaw === "no-prop" || isArray(referencesOfRaw) && referencesOfRaw.length === 0;
@@ -3049,7 +3048,7 @@ function parseJsonConfigFileContentWorker(
30493048

30503049
function getProjectReferences(basePath: string): readonly ProjectReference[] | undefined {
30513050
let projectReferences: ProjectReference[] | undefined;
3052-
const referencesOfRaw = getPropFromRaw<ProjectReference>("references", element => typeof element === "object", "object");
3051+
const referencesOfRaw = getPropFromRaw("references", (element): element is ProjectReference => !!element && typeof element === "object", "object");
30533052
if (isArray(referencesOfRaw)) {
30543053
for (const ref of referencesOfRaw) {
30553054
if (typeof ref.path !== "string") {
@@ -3077,11 +3076,12 @@ function parseJsonConfigFileContentWorker(
30773076
return getPropFromRaw(prop, isString, "string");
30783077
}
30793078

3080-
function getPropFromRaw<T>(prop: "files" | "include" | "exclude" | "references", validateElement: (value: unknown) => boolean, elementTypeName: string): PropOfRaw<T> {
3079+
function getPropFromRaw<T>(prop: "files" | "include" | "exclude" | "references", validateElement: (value: unknown) => value is T, elementTypeName: string): PropOfRaw<T> {
30813080
if (hasProperty(raw, prop) && !isNullOrUndefined(raw[prop])) {
3082-
if (isArray(raw[prop])) {
3083-
const result = raw[prop] as T[];
3084-
if (!sourceFile && !every(result, validateElement)) {
3081+
const value = raw[prop];
3082+
if (isArray(value)) {
3083+
const result = filter(value, validateElement);
3084+
if (!sourceFile && result.length !== value.length) {
30853085
errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, prop, elementTypeName));
30863086
}
30873087
return result;

0 commit comments

Comments
 (0)