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.

Detect unknown/undefined prop usage

See original GitHub issue

This is a proposal for enhancing vue-tsc

Example:

<MyComponent
    :propThatDoesNotExist="42"
/>

When running npx vue-tsc --noEmit i want it to detect that propThatDoesNotExist is not presently defined in myComponent. This could produce a warning or error.

Feature like this currently exists in TS files. When trying to edit fields that is not defined in some typescript class it will output: Property ‘xxx’ does not exist on type ‘MyClass’.

This would be very helpful for Vue developers when renaming props or performs refactoring or git rebases as looking through the code manually can be tedious.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:45 (16 by maintainers)

github_iconTop GitHub Comments

18reactions
henribrucommented, Jun 3, 2022

This isn’t just about fallthrough either, as shown in https://github.com/johnsoncodehk/volar/issues/1383 this is causing errors for many completely standard HTML attributes directly on the elements. It seems unreasonable requiring people to add custom declaration files to avoid that

18reactions
johnsoncodehkcommented, Jun 4, 2022

In 0.36, custom / unknown attrs types behavior handle responsibility will transfer to developer.

  • Expand custom attrs example
<template>
    <div myprop="a">
</template>
// env.d.ts
declare module '@vue/runtime-dom' {
    interface HTMLAttributes {
        myprop: string
    }
}

export { }
  • Allow any attrs
// env.d.ts

// for native html elements
declare module '@vue/runtime-dom' {
    interface HTMLAttributes {
        [key: string]: any
    }
    interface SVGAttributes {
        [key: string]: any
    }
}

// for vue components
declare module '@vue/runtime-core' {
    interface AllowedComponentProps {
        [key: string]: any
    }
}

export { }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Unknown Prop Warning - React
The unknown-prop warning will fire if you attempt to render a DOM element with a prop that is not recognized by React as...
Read more >
Check if props are undefined when loading component
Save this question. Show activity on this post. I have a question regarding checking if props are undefined in a functional component in...
Read more >
ReferenceError: reference to undefined property "x" - JavaScript
The JavaScript warning "reference to undefined property" occurs when a script attempted to access an object property which doesn't exist.
Read more >
Documentation - Everyday Types - TypeScript
To specify the type of an array like [1, 2, 3] , you can use the syntax ... from an optional property, you'll...
Read more >
useForm - watch - Simple React forms validation
Props ; string, Watch input value by name (similar to lodash get function) ; string[], Watch multiple inputs ; undefined, Watch all inputs...
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