Skip to content

Commit

Permalink
fix(type-utils): treat intrinsic types as if they are from lib
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaStevens committed Jun 15, 2023
1 parent e6235bf commit 6815b8c
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions packages/type-utils/src/TypeOrValueSpecifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,21 @@ function typeDeclaredInPackage(
);
return declarationFiles.some(declaration =>
matcher.test(declaration.fileName),
)
}

function typeDeclaredInLib(
declarationFiles: ts.SourceFile[],
program: ts.Program,
): boolean {
// Assertion: The type is not an error type.

// Intrinsic type (i.e. string, number, boolean, etc) - Treat it as if it's from lib.
if (declarationFiles.length === 0) {
return true;

Check warning on line 173 in packages/type-utils/src/TypeOrValueSpecifier.ts

View check run for this annotation

Codecov / codecov/patch

packages/type-utils/src/TypeOrValueSpecifier.ts#L173

Added line #L173 was not covered by tests
}
return declarationFiles.some(declaration =>
program.isSourceFileDefaultLibrary(declaration),
);
}

Expand All @@ -182,9 +197,7 @@ export function typeMatchesSpecifier(
case 'file':
return typeDeclaredInFile(specifier.path, declarationFiles, program);
case 'lib':
return declarationFiles.some(declaration =>
program.isSourceFileDefaultLibrary(declaration),
);
return typeDeclaredInLib(declarationFiles, program);
case 'package':
return typeDeclaredInPackage(specifier.package, declarationFiles);
}
Expand Down

0 comments on commit 6815b8c

Please sign in to comment.