Skip to content
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

RFC: @errorCode to provide context for errors for properties #422

Open
cmgriffing opened this issue Aug 23, 2024 · 0 comments
Open

RFC: @errorCode to provide context for errors for properties #422

cmgriffing opened this issue Aug 23, 2024 · 0 comments

Comments

@cmgriffing
Copy link

It would be nice to be able to inform users when they encounter specific errors related to a property.

In this example use case, we would like to inform the user that a property on a discriminated union can only be set when the discriminator matches the type.

interface Base {
  discriminator: boolean;
  foo: string | never;
}

interface UnionTypeA extends Base {
  discriminator: true;
  foo: string;
}

interface UnionTypeB extends Base {
  discriminator: false;

  /**
   *
   * {@errorCode 2322 | This property can only be set when discriminator is equal to `true`}
   *
   */
  foo: never;
}

type DiscriminatedUnion = UnionTypeA | UnionTypeB;

const bar: DiscriminatedUnion = {
  discriminator: false,
  foo: ""
}

The current error is shown as:
Screenshot 2024-08-23 at 11 35 35 AM

I based the syntax around what I have seen as prior art in the @link tag.

Apologies if this has been suggested or discussed before, I could not find anything from an initial search of issues.

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

No branches or pull requests

1 participant