feat(types): expose ElementAttributesProperty for TSX#9379
feat(types): expose ElementAttributesProperty for TSX#9379andoshin11 wants to merge 1 commit intovuejs:devfrom
Conversation
afa69a4 to
9a38c4f
Compare
|
oops... fixing errors |
|
Thanks for your amazing work! I briefly looked into it and it would be so useful for TSX users! As a side note, in Vue v3, we can declare |
|
Any chance of this working along with https://github.com/kaorun343/vue-property-decorator? It's the only way I found to enable typehinting and autocompletion in my editor. |
|
Maybe we can't use the import { Vue, Component, Prop } from 'vue-property-decorator'
const YourComponentProps = Vue.props({
propA: Number,
propB: { type: String, default: 'default value' },
propC: [String, Boolean],
});
@Component
export default class YourComponent extends Vue<YourComponentProps> {
get text() {
return `${this.propA} ${this.propB} ${this.propC}`;
}
} |
Some benefits: - Better editor and tooling support - No need for `h: CreateElement` in any `render()` - Can format/lint the code - In the future, can remove usage of `components` if vuejs/vue#9379 is merged - Use single css classes (copied from tachyons) to style components, since most of the styling can be done with Vuetify, also remove `sass` and `sass-loader`
|
@baocancode did you see the conflicting file blocking the automated checks? |
|
I left this PR wondering for too much time. I'll close this until Vue 3 comes along. |
What kind of change does this PR introduce? (check at least one)
Does this PR introduce a breaking change? (check one)
If yes, please describe the impact and migration path for existing applications:
The PR fulfills these requirements:
devbranch for v2.x (or to a previous version branch), not themasterbranchfix #xxx[,#xxx], where "xxx" is the issue number)If adding a new feature, the PR's description includes:
Descriptions
With current type definitions, it's extremely difficult for developers to pass props to children components when writing TSX since there's no exposed property that JSX can handle as element attributes properties.
This PullRequest achieves 2 things.
_attrsto theExtendedVuetype so it can be used insideJSX.ElementAttributesProperty.(Examples are below)propsinterface.Example
Given these 2 children components...
and prepare
shims-tsx.d.tslike thisProperty completion works as expected.
Type error warned as expected.
and no more errors with correct props declaration 👍