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.

Trailing comma error with prop typing

See original GitHub issue

I’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:closed
  • Created 4 years ago
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lukasborawskicommented, Feb 17, 2020

@kevinmarrec @rcheung9 I’ve made a workaround, it was also recommended in few places:

const menuProp: PropOptions<Menu> = {
  type: Array,
  required: true,
}

props: {
  menuProp,
},

Got the same type of issue with the data object so the solution could look like that:

data: (): Navigation => ({
  subnav: [],
}),

and Navigation is a component interface. It works fine for me.

Also, I’ve moved to TSLint parser.

// .eslintrc.js
parserOptions: {
  parser: '@typescript-eslint/parser',
},
0reactions
kevinmarreccommented, Feb 17, 2020

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

Read more comments on GitHub >

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

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