Trailing comma error with prop typing
See original GitHub issueI’m using Typescript with Vue. I want to add typing for my props but lint giving me an error with trailing comma. In this case:
21:6 error Parsing error: Unexpected token, expected ","
9 | type: Object,
10 | required: true
> 11 | } as PropOptions<MenuItem[]>,
| ^
12 | },
13 | data: () => ({}),
14 | })
Code:
<script lang="ts">
import Vue, { PropOptions } from 'vue'
import { MenuItem } from '~/types/data'
export default Vue.extend({
name: 'UiSubmenu',
props: {
submenuProp: {
type: Object,
required: true,
} as PropOptions<MenuItem[]>,
},
data: () => ({}),
})
</script>
I’ve tried to disabled the comma-dangle rule but no results.
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (3 by maintainers)
Top Results From Across the Web
Trailing comma error with prop typing in Vue.js - Stack Overflow
The problem is your typescript syntax. You must type your props with a function that returns the right type.
Read more >Trailing commas - JavaScript - MDN Web Docs
JavaScript allows trailing commas wherever a comma-separated list of values is accepted and more values may be expected after the last item.
Read more >When designating propTypes why do we include a coma at ...
Hey Brian! It's not necessary to type a trailing comma. It's just become conventional, because it's easier to reorder properties and debug ...
Read more >Best practices for using trailing commas in JavaScript
A trailing comma, also known as a dangling or terminal comma, is a comma symbol that is typed after the last item of...
Read more >trailing-comma - Rule
Requires or disallows trailing commas in array and object literals, destructuring assignments, function typings, named imports and exports and function ...
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
@kevinmarrec @rcheung9 I’ve made a workaround, it was also recommended in few places:
Got the same type of issue with the data object so the solution could look like that:
and
Navigation
is a component interface. It works fine for me.Also, I’ve moved to TSLint parser.
Closing as i’m pretty sure it’s duplicate of https://github.com/nuxt/typescript/issues/136 Instructions about removing
eslint
are clear in https://typescript.nuxtjs.org/guide/lint.html