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

(feat) be able to type props/events/slots #437

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dummdidumm
Copy link
Member

@dummdidumm dummdidumm commented Aug 10, 2020

Through a new reserved interface ComponentDef

See new tests for examples.

Generics

Problem to be solved: Generics. We cannot use instanceOf(ComponentName) anymore, because this way we cannot pass in the information about the type of the generic.

If we have

Child:

<script lang="ts">
   interface ComponentDef<T> {
        props: {items: T[]},
        events: {itemClick: CustomEvent<T>;}
        slots: {}
   }
</script>
// ...

Parent:

<Child items="{['a', 'stringarray']}" on:itemClick="{iShouldBeOfTypeString => ...}" />

We need a transformation that makes sure that iShouldBeOfTypeString actually is inferred as string. My current idea is to transform this to new Child({props: {...allPropsAndItsValuesThatAreDefinedOnTheChild}}).$on instead of the old instanceOf(Child).$on.

A completely different idea is to somehow use Function Components instead of Class components. But I'm not sure if we can use this with all the other constraints we have.

Thoughts?

Through a new reserved interface "ComponentDef"
@jasonlyu123
Copy link
Member

Maybe we can add a dummy helper function like __sveltets_norename or __sveltets_generated to retain the no-rename of old instanceOf

@Evertt
Copy link

Evertt commented Mar 16, 2021

Hey guys, any idea when this will be completed? 👼
I'm running up against this very issue right now and for now I'm just using any instead of a generic type, but you know, a generic type would be nice. 😁

@dummdidumm
Copy link
Member Author

This implementation will very likely not land in this form. This RFC is where the discussion is happening and the details are specified. After that the implementation will follow.

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

3 participants