Skip to content

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.

3 participants