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

fix: move svelteHTML to load the correct svelte/element #9070

Merged
merged 8 commits into from
Aug 11, 2023

Conversation

jasonlyu123
Copy link
Member

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

For sveltejs/language-tools#2109. This file is currently in the language-tools repo and ships with svelte2tsx, but the problem is that TypeScript will load the svelte/elements version that comes with the svelte-language-server. Moving this to the Svelte core makes TypeScript always resolve it to the user-installed/workspace version of Svelte. Making it resolve to the user version also fixes the problem with the declaration merging of declare module "svelte/elements". This allows the user/library to add custom types with it. For example:

// app.d.ts
import { HTMLButtonAttributes } from 'svelte/elements'

declare module 'svelte/elements' {
    export interface SvelteHTMLElements {
        'custom-button': HTMLButtonAttributes;
    }

    export interface HTMLButtonAttributes {
        'veryexperimentalattribute': string;
    }
}

This file is meant to be loaded by ts or svelte-language-server. It's not meant to be user-facing. So this doesn't need to be in the package.json export and doesn't need documentation on its usage. @dummdidumm What do you think about the file naming and the declare module thing?

so it can be extend with declare module
converting to module so it can extend without needing another type alias
@changeset-bot
Copy link

changeset-bot bot commented Aug 4, 2023

🦋 Changeset detected

Latest commit: 272909b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name sounds good to me! I'm not sure what you mean by the "declare module thing"? Do you mean that people are now able to extend svelte/elements? Because yes, that's a great side effect of this.

Btw this needs a changeset.

packages/svelte/svelte-html.d.ts Outdated Show resolved Hide resolved
packages/svelte/svelte-html.d.ts Show resolved Hide resolved
@jasonlyu123 jasonlyu123 marked this pull request as ready for review August 4, 2023 09:17
@dummdidumm
Copy link
Member

Looks good! Let's try this out locally first by adjusting the language-tools and trying it on a local copy of Svelte.

@dummdidumm dummdidumm merged commit 05f99d2 into sveltejs:master Aug 11, 2023
6 checks passed
@github-actions github-actions bot mentioned this pull request Aug 11, 2023
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.

2 participants