You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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: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
.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
The text was updated successfully, but these errors were encountered: