Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infer attrs for implementing HOCs #477

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

rudyxu1102
Copy link

@rudyxu1102 rudyxu1102 commented Jan 1, 2023

Summary

Allowing to infer attrs by using attrs option of defineComponent or defineCustomElement.
And in the setup-script, passing generic type in the defineAttrs<T> will also infer attrs to T.

defineComponent

const Comp = defineComponent({
  props: {
    foo: String
  },
  attrs: Object as AttrsType<{
    bar?: number
  }>,
  created() {
    this.$attrs.bar // number | undefined
  }
});

<Comp foo={'str'} bar={1} />;

Setup Script

<script setup lang="ts">
const attrs = defineAttrs<{ bar?: number }>();
</script>

Links

Important: Do NOT comment on this PR. Please use the discussion thread linked above to provide feedback, as it provides branched discussions that are easier to follow.This also makes the edit history of the PR clearer.

@rudyxu1102 rudyxu1102 changed the title Inferred attrs Infer attrs for HOCs Sep 28, 2023
@rudyxu1102 rudyxu1102 changed the title Infer attrs for HOCs Infer attrs for implementing HOCs Sep 29, 2023
@pikax pikax mentioned this pull request Dec 12, 2023
28 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant