Skip to content

fix: prevent infinite recursion with NoUndefined and RecursiveRequired re: DocumentType #1455

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

Merged
merged 2 commits into from
Nov 14, 2024

Conversation

gschwart
Copy link
Contributor

Issue #, if available:

Description of changes:

When trying to use AssertiveClient or UncheckedClient for a request that contains a field of type DocumentType results in the following TypeScript error:

 error TS2589: Type instantiation is excessively deep and possibly infinite.

Cause

Inside the AssertiveClient type definition, the NoUndefined type:

export type NoUndefined<T> = T extends Function ? T : [T] extends [object] ? {
    [key in keyof T]: NoUndefined<T[key]>;
} : Exclude<T, undefined>;

recursively iterates excluding undefined. The issue stems from the type DocumentType since it is self-referential which results in an infinite loop.

export type DocumentType = null | boolean | number | string | DocumentType[] | {
    [prop: string]: DocumentType;
};

Fix

Update the NoUndefined and RecursiveRequired types to ignore DocumentType fields:

export type NoUndefined<T> = T extends Function
  ? T 
  : T extends DocumentType
  ? T 
  : [T] extends [object]
    ? {
        [key in keyof T]: NoUndefined<T[key]>;
      }
    : Exclude<T, undefined>;

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@gschwart gschwart requested a review from a team as a code owner November 14, 2024 18:43
@kuhe kuhe merged commit fcd5ca8 into smithy-lang:main Nov 14, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants