-
Notifications
You must be signed in to change notification settings - Fork 235
fix: omit utility type with recursive interfaces causing stack overflow #2426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
11
commits into
next
Choose a base branch
from
copilot/fix-omit-type-regression
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a7f83e8
Initial plan
Copilot 5da19a8
Set up test environment and reproduce Omit type recursion issue
Copilot d64176a
Fix Omit type with recursive interfaces by skipping lib utility types…
Copilot 89ded07
Add null safety checks to address code review feedback
Copilot 4c1b725
Refactor lib file detection into reusable helper function
Copilot ad79c0e
Address code review feedback: extract regex constant, improve error m…
Copilot 6b7a477
Check all declarations when detecting lib types instead of just the f…
Copilot b3221ea
Address PR feedback: use native fs.globSync and LogicError class
Copilot 4075d29
Use isTypeScriptLibFile helper and add complex test examples
Copilot 162c0a3
Fix CI failures: add Node 20 compatibility and format code
Copilot c646d44
Remove glob fallback and require Node 22+
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import type ts from "typescript"; | ||
|
|
||
| /** | ||
| * Regular expression pattern for detecting TypeScript lib files. | ||
| * Matches file paths like: /path/to/typescript/lib/lib.es5.d.ts | ||
| */ | ||
| export const TYPESCRIPT_LIB_FILE_PATTERN = /[/\\]typescript[/\\]lib[/\\]lib\.[^/\\]+\.d\.ts$/i; | ||
|
|
||
| /** | ||
| * Checks if a source file is part of the TypeScript standard library. | ||
| * This is used to identify utility types (like Omit, Pick, Exclude, etc.) | ||
| * that should be treated specially to avoid infinite recursion issues. | ||
| * | ||
| * @param sourceFile The source file to check | ||
| * @returns true if the file is a TypeScript lib file, false otherwise | ||
| */ | ||
| export function isTypeScriptLibFile(sourceFile: ts.SourceFile | undefined): boolean { | ||
| if (!sourceFile) { | ||
| return false; | ||
| } | ||
|
|
||
| return TYPESCRIPT_LIB_FILE_PATTERN.test(sourceFile.fileName); | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import { assertValidSchema } from "../../utils"; | ||
| import { test } from "node:test"; | ||
|
|
||
| test("valid-data - type-omit-recursive", assertValidSchema("type-omit-recursive", "IFormProps")); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // Test case for Omit with recursive interfaces | ||
| // This ensures that when an interface extends Omit<RecursiveType, 'property'>, | ||
| // the schema generator correctly handles the utility type without infinite recursion | ||
|
|
||
| interface IItems { | ||
| items?: IItems; | ||
| value: string; | ||
| } | ||
|
|
||
| // IFormProps extends Omit<IItems, 'items'> should only have the 'value' property | ||
| // The 'items' property is correctly omitted | ||
| export interface IFormProps extends Omit<IItems, 'items'> { | ||
| } | ||
|
|
||
| // Note: More complex cases with conditional types and infer (like ArrayElement<T>) | ||
|
arthurfiorette marked this conversation as resolved.
Outdated
|
||
| // may still cause issues and are tracked separately | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| { | ||
| "$ref": "#/definitions/IFormProps", | ||
| "$schema": "http://json-schema.org/draft-07/schema#", | ||
| "definitions": { | ||
| "IFormProps": { | ||
| "additionalProperties": false, | ||
| "properties": { | ||
| "value": { | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "required": [ | ||
| "value" | ||
| ], | ||
| "type": "object" | ||
| } | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.