question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Suggestion: @Prop uses TS for type and default

See original GitHub issue

Currently 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:closed
  • Created 5 years ago
  • Reactions:11
  • Comments:32 (24 by maintainers)

github_iconTop GitHub Comments

14reactions
kaorun343commented, Mar 21, 2019

Please check the latest version, v8.1.0.

7reactions
sunyatasattvacommented, Jan 15, 2019

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:

@Prop({ default: 'default', type: String }) myProperty: string = 'default';

when this is much more succinct and meaningful:

@Prop() myProperty: string = 'default';

And the desired output would be something like:

props: {
    myProperty: {
      type: String,
      default: 'default'
    }
  }
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found