fix: crash in getWellKnownSymbolPropertyOfType for mapped typeof symbol#698
Merged
Conversation
kirkwaiblinger
approved these changes
Jan 31, 2025
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #698 +/- ##
==========================================
+ Coverage 76.98% 77.20% +0.21%
==========================================
Files 50 50
Lines 4979 5000 +21
Branches 680 687 +7
==========================================
+ Hits 3833 3860 +27
+ Misses 1145 1139 -6
Partials 1 1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
ronami
approved these changes
Jan 31, 2025
| declare const x: { | ||
| [Symbol.asyncIterator](): AsyncIterator<any>; | ||
| }> | ||
| }; |
Collaborator
There was a problem hiding this comment.
Wdyt about adding the following (or similar) to createSourceFileAndTypeChecker() so issues like this would be easier to notice (probably on a separate PR, I'll be happy to send one):
export function createSourceFileAndTypeChecker(
sourceText: string,
fileName = "file.tsx",
): SourceFileAndTypeChecker {
const compilerOptions: ts.CompilerOptions = {
lib: ["ES2018"],
target: ts.ScriptTarget.ES2018,
};
const fsMap = tsvfs.createDefaultMapFromNodeModules(compilerOptions, ts);
fsMap.set(fileName, sourceText);
const system = tsvfs.createSystem(fsMap);
const env = tsvfs.createVirtualTypeScriptEnvironment(
system,
[fileName],
ts,
compilerOptions,
);
const program = env.languageService.getProgram();
if (program === undefined) {
throw new Error("Failed to get program.");
}
+ const diagnostics = program.getSyntacticDiagnostics();
+
+ if (diagnostics.length > 0) {
+ throw new Error(
+ ts.flattenDiagnosticMessageText(
+ diagnostics[0].messageText,
+ ts.sys.newLine,
+ ),
+ );
+ }
return {
sourceFile: program.getSourceFile(fileName)!,
typeChecker: program.getTypeChecker(),
};
}
Owner
Author
There was a problem hiding this comment.
Good idea, I'd like that!
RebeccaStevens
approved these changes
Jan 31, 2025
3 tasks
JoshuaKGoldberg
pushed a commit
that referenced
this pull request
Feb 5, 2025
…as valid syntax (#703) <!-- 👋 Hi, thanks for sending a PR to ts-api-utils! 💖. Please fill out all fields below and make sure each item is true and [x] checked. Otherwise we may not be able to review your PR. --> ## PR Checklist - [ ] Addresses an existing open issue: fixes #000 - [ ] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/ts-api-utils/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/ts-api-utils/blob/main/.github/CONTRIBUTING.md) were taken ## Overview <!-- Description of what is changed and how the code change does that. --> This is a small follow-up to #698 (comment), and it adjusts the test helper `createSourceFileAndTypeChecker` to check that passed syntax is valid (to prevent accidental invalid syntax on test cases). I've checked locally that this would fail before the change on the linked comment. --- Codecov fails on this, but I don't think there's much to do (it's a test helper, should it even be included in the codecov report?).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
status: accepting prsOverview
As seen in typescript-eslint/typescript-eslint#10747, we can't assume that prop's declarations array can be found. If the type being checked is a mapped type over the requested well-known symbol, it'll come up as
undefined.💖