-
Notifications
You must be signed in to change notification settings - Fork 394
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
feat(engine): improve createElement() second parameter error messages #944
Conversation
Benchmark resultsBase commit: lwc-engine-benchmark
|
if (!isObject(options) || isNull(options)) { | ||
throw new TypeError(); | ||
throw new TypeError(`"createElement" function was invoked with invalid second parameter "${options}". Expected an object that contains property "is" mapped to an object that extends LightningElement from "lwc".`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you have to call ${toString(options)}
in case the argument can't be transformed into a string.
|
||
if (isNull(Ctor) || isUndefined(Ctor)) { | ||
throw new TypeError( | ||
`"createElement" function was invoked with invalid second parameter. "is" property value was "${Ctor}", but expected an object that extends LightningElement from "lwc". ` + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toString on the Ctor
if (!isObject(options) || isNull(options)) { | ||
throw new TypeError(); | ||
throw new TypeError(`"createElement" function was invoked with invalid second parameter "${options}". Expected an object that contains property "is" mapped to an object that extends LightningElement from "lwc".`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should keep the first error message minimal and focussed. Something like sound be enough:
"createElement" expects an object as second parameter.
If we were to add another required parameters to createElement
we would need to update both error messages with the error messages you proposed.
|
||
if (isNull(Ctor) || isUndefined(Ctor)) { | ||
throw new TypeError( | ||
`"createElement" function was invoked with invalid second parameter. "is" property value was "${Ctor}", but expected an object that extends LightningElement from "lwc". ` + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error is inaccurate here: You probably forgot to add the extend clause on the class declaration.
. We are only checking if the is
property is not null or undefined.
Since we are validating if the is
value in getComponentDef
, we should only warn if the Ctor
is from the wrong type.
} | ||
|
||
let Ctor = (options as any).is as ComponentConstructor; | ||
|
||
if (isNull(Ctor) || isUndefined(Ctor)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of checking if the function is null or undefined, I would rather check if the Ctor
is a function.
Benchmark resultsBase commit: lwc-engine-benchmark
|
Details
Improve createElement second parameter validation. Fixes #940
Does this PR introduce a breaking change?