Specifying default value stimulus unclear error message
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 13.1k
- Forks
- 441
- PR merge metrics
- No merged PRs in 30d
Description
When specifying values on controller, there's in console very unclear message that can waste your time debugging.
So passing the following value in controller
export default class extends Controller {
static values = {
turboFrameName: { type: String },
}
}
will produce
Uncaught Error: Type "string" must match the type of the default value. Given default value: "undefined" as "undefined"
Actually I thought that those two constructions are identical
plain type and the above specified as hash
export default class extends Controller {
static values = {
turboFrameName: String,
}
For me the error message looks something unclear and I don't understand what should be done (in fact it was just typo for me, I didn't know that this construction with hash options can only be used with default option)
There are 2 solutions in my opinion:
- Adjust error message something like: Value "turboFrameName" with type "string" missing default value. Given default value: "undefined"
- Allow both constructions to be used visa-versa, with and without default value, and specify default value only if you need one, but not throw uncaught error
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the controller values examples from the issue and inspect the validation path that handles a type-only value versus an options object. Done means either the missing-default error clearly identifies the value, type, and required default, or both forms are accepted consistently; the issue does not specify files or tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100