Suggestion: @Prop uses TS for type and default
See original GitHub issueCurrently we have to write:
@Prop({type: Number, default: 1) some!: number
.
It would be way more logical and readable to just infer type and default from it’s value.
@Prop() some: number = 1
I know that you don’t have to specify the types if you assign a value right away. Isn’t it possible to get the value and type and pass them to vue? Currently we don’t even get a warning if we pass a String to that property if it’s not specified in the annotations type. I assumed that exactly this was the argument to go for typescript.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:11
- Comments:32 (24 by maintainers)
Top Results From Across the Web
Typing defaultProps - React TypeScript Cheatsheets
The consensus is to use object default values. ... See this in TS Playground ... utility type) but the recommendation is to "reverse"...
Read more >Default Props in React/TypeScript - DEV Community
This is necessary because, if we neglect to list, say, requiredString in the interface, then TS won't know what type to assign to...
Read more >How to specify (optional) default props with TypeScript for ...
I'm trying to create a stateless React component with optional props and defaultProps in Typescript (for a React Native ...
Read more >React with TypeScript: Optional Props with Default Values
When using TypeScript with React, it's easy enough to define ... to the final props interface we would use to actually type the...
Read more >Default values for props with script setup and TypeScript
Any suggestions? <script setup="props" lang="ts"> import { computed } from 'vue' // declare props using TypeScript syntax // this will be ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Please check the latest version,
v8.1.0
.Any news about this issue from the maintainer @kaorun343 ? I’d +1 both OP and @eddow here. It seems wasteful, duplicated and error-prone to do something like:
when this is much more succinct and meaningful:
And the desired output would be something like: