Skip to content

Commit d46653a

Browse files
author
Andy
authored
Handle undefined input to firstDefined (#21300)
1 parent 1c9cd96 commit d46653a

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6562,7 +6562,7 @@ namespace ts {
65626562
// b) It references `arguments` somewhere
65636563
const lastParam = lastOrUndefined(declaration.parameters);
65646564
const lastParamTags = lastParam && getJSDocParameterTags(lastParam);
6565-
const lastParamVariadicType = lastParamTags && firstDefined(lastParamTags, p =>
6565+
const lastParamVariadicType = firstDefined(lastParamTags, p =>
65666566
p.typeExpression && isJSDocVariadicType(p.typeExpression.type) ? p.typeExpression.type : undefined);
65676567
if (!lastParamVariadicType && !containsArgumentsReference(declaration)) {
65686568
return false;

src/compiler/core.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ namespace ts {
183183

184184
/** Like `forEach`, but suitable for use with numbers and strings (which may be falsy). */
185185
export function firstDefined<T, U>(array: ReadonlyArray<T> | undefined, callback: (element: T, index: number) => U | undefined): U | undefined {
186+
if (array === undefined) {
187+
return undefined;
188+
}
189+
186190
for (let i = 0; i < array.length; i++) {
187191
const result = callback(array[i], i);
188192
if (result !== undefined) {

src/services/codefixes/importFixes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ namespace ts.codefix {
467467
addJsExtension: boolean,
468468
): string | undefined {
469469
const roots = getEffectiveTypeRoots(options, host);
470-
return roots && firstDefined(roots, unNormalizedTypeRoot => {
470+
return firstDefined(roots, unNormalizedTypeRoot => {
471471
const typeRoot = toPath(unNormalizedTypeRoot, /*basePath*/ undefined, getCanonicalFileName);
472472
if (startsWith(moduleFileName, typeRoot)) {
473473
return removeExtensionAndIndexPostFix(moduleFileName.substring(typeRoot.length + 1), options, addJsExtension);

0 commit comments

Comments
 (0)