diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index b331241660c..301130a3084 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2292,7 +2292,14 @@ "category": "Error", "code": 5062 }, - + "Substututions for patterns '{0}' should be an array.": { + "category": "Error", + "code": 5063 + }, + "Substitution '{0}' for pattern '{1}' has incorrect type, expected 'string', got '{2}'.": { + "category": "Error", + "code": 5064 + }, "Concatenate and emit output to single file.": { "category": "Message", "code": 6001 diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 8d0e8b296e1..9d99f2873af 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1985,11 +1985,22 @@ namespace ts { if (!hasZeroOrOneAsteriskCharacter(key)) { programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Pattern_0_can_have_at_most_one_Asterisk_character, key)); } - for (const subst of options.paths[key]) { - if (!hasZeroOrOneAsteriskCharacter(subst)) { - programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Substitution_0_in_pattern_1_in_can_have_at_most_one_Asterisk_character, subst, key)); + if (isArray(options.paths[key])) { + for (const subst of options.paths[key]) { + const typeOfSubst = typeof subst; + if (typeOfSubst === "string") { + if (!hasZeroOrOneAsteriskCharacter(subst)) { + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Substitution_0_in_pattern_1_in_can_have_at_most_one_Asterisk_character, subst, key)); + } + } + else { + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Substitution_0_for_pattern_1_has_incorrect_type_expected_string_got_2, subst, key, typeOfSubst)); + } } } + else { + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Substututions_for_patterns_0_should_be_an_array, key)); + } } } diff --git a/tests/baselines/reference/pathsValidation1.errors.txt b/tests/baselines/reference/pathsValidation1.errors.txt new file mode 100644 index 00000000000..8b82f117353 --- /dev/null +++ b/tests/baselines/reference/pathsValidation1.errors.txt @@ -0,0 +1,6 @@ +error TS5063: Substututions for patterns '*' should be an array. + + +!!! error TS5063: Substututions for patterns '*' should be an array. +==== tests/cases/compiler/a.ts (0 errors) ==== + let x = 1; \ No newline at end of file diff --git a/tests/baselines/reference/pathsValidation1.js b/tests/baselines/reference/pathsValidation1.js new file mode 100644 index 00000000000..bfffc647f63 --- /dev/null +++ b/tests/baselines/reference/pathsValidation1.js @@ -0,0 +1,5 @@ +//// [a.ts] +let x = 1; + +//// [a.js] +var x = 1; diff --git a/tests/baselines/reference/pathsValidation2.errors.txt b/tests/baselines/reference/pathsValidation2.errors.txt new file mode 100644 index 00000000000..8956b2fc159 --- /dev/null +++ b/tests/baselines/reference/pathsValidation2.errors.txt @@ -0,0 +1,6 @@ +error TS5064: Substitution '1' for pattern '*' has incorrect type, expected 'string', got 'number'. + + +!!! error TS5064: Substitution '1' for pattern '*' has incorrect type, expected 'string', got 'number'. +==== tests/cases/compiler/a.ts (0 errors) ==== + let x = 1; \ No newline at end of file diff --git a/tests/baselines/reference/pathsValidation2.js b/tests/baselines/reference/pathsValidation2.js new file mode 100644 index 00000000000..bfffc647f63 --- /dev/null +++ b/tests/baselines/reference/pathsValidation2.js @@ -0,0 +1,5 @@ +//// [a.ts] +let x = 1; + +//// [a.js] +var x = 1; diff --git a/tests/cases/compiler/pathsValidation1.ts b/tests/cases/compiler/pathsValidation1.ts new file mode 100644 index 00000000000..45a4409cf03 --- /dev/null +++ b/tests/cases/compiler/pathsValidation1.ts @@ -0,0 +1,11 @@ +// @filename: tsconfig.json +{ + "compilerOptions": { + "baseUrl": ".", + "paths": { + "*": "*" + } + } +} +// @filename: a.ts +let x = 1; \ No newline at end of file diff --git a/tests/cases/compiler/pathsValidation2.ts b/tests/cases/compiler/pathsValidation2.ts new file mode 100644 index 00000000000..b15ad4e236a --- /dev/null +++ b/tests/cases/compiler/pathsValidation2.ts @@ -0,0 +1,11 @@ +// @filename: tsconfig.json +{ + "compilerOptions": { + "baseUrl": ".", + "paths": { + "*": [1] + } + } +} +// @filename: a.ts +let x = 1; \ No newline at end of file