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

Improve error messaging on InvalidProp #94

Open
davesnx opened this issue Dec 29, 2021 · 0 comments
Open

Improve error messaging on InvalidProp #94

davesnx opened this issue Dec 29, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@davesnx
Copy link
Member

davesnx commented Dec 29, 2021

Errors look like this

→ ~/C/g/r/jsoo-react on Type-safe-html-tags ✗ make

File "test.ml", lines 109-111, characters 2-10:
109 | ..((div ~cols:1 ~href:(("https://example.com")
110 |       [@reason.raw_literal "https://example.com"]) ~children:[foo] ())
111 |   [@JSX ])
Error: prop 'cols' isn't a valid prop for a 'div'

TypeScript version, from the current type-checked from TS

Type '{ children: Element[]; classId: string; }' is not assignable to type 'DetailedHTMLProps<ObjectHTMLAttributes<HTMLObjectElement>, HTMLObjectElement>'.
  Property 'classId' does not exist on type 'DetailedHTMLProps<ObjectHTMLAttributes<HTMLObjectElement>, HTMLObjectElement>'. Did you mean 'classID'?

We could aim to have a similar output as our type-checker but I believe is rather useless, the output on the labelled argument being miss-spelt or unknown looks like https://rescript-lang.org/try?code=DwIwrgLhD2B2AEAbaiCGBeAzAPngbwFsBnAcwFpsAlAU1QGMIA6IiAJwEtYSBfeYAenBQ42AFBA

Maybe we could aim for something more simple:

File "test.ml", lines 109-111, characters 2-10:
109 | ..((div ~cols:1 ~href:(("https://example.com")
110 |       [@reason.raw_literal "https://example.com"]) ~children:[foo] ())
111 |   [@JSX ])
Error: 'div' contains an invalid prop: 'cols'.
It only accepts 'Global attributes' defined in https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes

and including a fancy Levenshtein distance with the rest of the props from the element: Maybe you mean xxxx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant