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

Svelte files that use typescript should allow typescript in inline handlers in the template section. #8611

Closed
PeytonHanel opened this issue May 21, 2023 · 1 comment

Comments

@PeytonHanel
Copy link

PeytonHanel commented May 21, 2023

Describe the problem

I use typescript in Svelte by creating a script tag like this <script lang='ts'>, but unintuitively this doesn't allow typescript to be used in the template section with inline handlers. Here is an example:

<button on:click={() => {
          let n: number = 1; // <--- underlines with an error squiggly 
}}>Accept</button>

But even more unintuitively, if I'm accessing a property that might not be there, for example, the parent form from the event, I can hide the red squiggly error with // @ts-ignore.

<form
    action='?/acceptFollowRequest'
    method='post'
  >
    <button class='btn-small' on:click={(event) => {
      // @ts-ignore
      console.log(event.target.form);  // <--- would normally red underline
    }}>Accept</button>
  </form> 

Describe the proposed solution

Any code inline in the template section should match the <script lang='ts'> declaration at the top of the file.

Alternatives considered

The current alternative is to just use javascript, or instead write out a function in the <script lang='ts'> tag. These are both ok solutions but I feel that my feature request would make Svelte more consistent and intuitive in the long run.

Importance

nice to have

@gtm-nayan
Copy link
Contributor

Duplicate of #4701

@gtm-nayan gtm-nayan marked this as a duplicate of #4701 May 21, 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

No branches or pull requests

2 participants