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

[feature request] Custom type-error messages #13713

Closed
devdoomari opened this issue Jan 27, 2017 · 1 comment
Closed

[feature request] Custom type-error messages #13713

devdoomari opened this issue Jan 27, 2017 · 1 comment
Labels
Declined The issue was declined as something which matches the TypeScript vision

Comments

@devdoomari
Copy link

devdoomari commented Jan 27, 2017

Hi!
I'm making a reactive version of Pixi.JS library.
I've got typescript to check for 'invalid' hierarchy - e.g. Graphics can be 'parent' of Circle, while the opposite way would be a type error.
But I'd like to add custom error messages that would be emitted by TS compiler for better library user-experience
(e.g. 'Circle component cannot be a valid parent of Graphics' alongside 'Circle does not implement IParentablyBy<Graphics>' ), but couldn't find any typescript articles on this.


EDIT:
So I'm looking for someone else to propose some typescript syntax that would provide some ways to provide custom type-level error messages, which would definitely be better than the sample one below:

export function createComponent<
  BlueprintClass extends BaseBlueprint,
  PropsType extends BasePropsType
>(
  blueprintClass: {
    new(): BlueprintClass & IParentableBy<BaseBlueprint, BasePropsType> 
  }
) {
  type ParentableByBlueprint = IParentableBy<
       BlueprintClass as ChildBlueprintClass, 
       BasePropsType
   > withCustomTypeErrorMessage( // THIS would be the magic sauce I'm hoping for
        ts.typeErrors.invalidGenerics(childBlueprintClass),
        `${ChildBlueprintClass} cannot be a child of ${BlueprintClass}`
   );
   // above isn't even a valid ts syntax - I'm making up above, but you get the idea (hopefully)
  return function _componentMetaData(
    props: PropsType,
    children: Array<
      RenderableType<
        BasePropsType,
        BaseBlueprint & ParentableByBlueprint
      >
    >
  ): RenderableType<PropsType, BlueprintClass> {
    return {
      blueprint: blueprintClass,
      props,
      children,
    };
  }
}

ps: Is there already a way to 'customize' typescript error messages? (or at least provide extra type-error messages?)

pps: I'd love to have them in-code (so typescript-compiler would actually type-check custom-error messages too), with options to get further error-info ('digging-into') to actually get to the raw error messages by TS compiler.

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label May 24, 2017
@RyanCavanaugh RyanCavanaugh added Declined The issue was declined as something which matches the TypeScript vision and removed Needs Investigation This issue needs a team member to investigate its status. labels Jul 23, 2019
@RyanCavanaugh
Copy link
Member

#23689 is the closest we'd come to this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Declined The issue was declined as something which matches the TypeScript vision
Projects
None yet
Development

No branches or pull requests

2 participants