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

New rule: require-slot-types #347

Closed
marekdedic opened this issue Jan 22, 2023 · 2 comments · Fixed by #368
Closed

New rule: require-slot-types #347

marekdedic opened this issue Jan 22, 2023 · 2 comments · Fixed by #368
Labels
enhancement New feature or request help wanted Extra attention is needed new rule

Comments

@marekdedic
Copy link
Contributor

marekdedic commented Jan 22, 2023

Motivation

It is possible to add types to component slots and their props:

<script lang="ts">
    interface $$Slots {
        default: { prop: boolean; };
    }
</script>

<slot prop={true} />

I would like to propose a rule to enforce these slot types.

Description

The rule should report any component that includes a <slot> and does not declare the $$Slots interface.

Examples

<!-- ✓ GOOD -->
<script>
</script>

<b>No slots here!</b>



<script>
  interface $$Slots {
    default: Record<string, never>;
  }
</script>

<slot />




<script lang="ts">
    interface $$Slots {
        default: { prop: boolean; };
    }
</script>

<slot prop={true} />


<script lang="ts">
    interface $$Slots {
        named: Record<string, never>;
    }
</script>

<slot name = "named" />

<!-- ✗ BAD -->
<script>
</script>

<slot />

Additional comments

The relevant RFC.

@marekdedic marekdedic added enhancement New feature or request new rule labels Jan 22, 2023
@ota-meshi
Copy link
Member

Memo:
New rule should be marked as experimental until the RFC is merged.
sveltejs/rfcs#38

See also: #345 (comment)

@ota-meshi ota-meshi added the help wanted Extra attention is needed label Jan 23, 2023
@marekdedic
Copy link
Contributor Author

Relevant PR: sveltejs/language-tools#1058

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed new rule
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants