sveltejs/svelte-preprocess

Variables created with Pug/Svelte mixin +each are not recognized by Typescript

Open

#207 aperta il 31 lug 2020

Vedi su GitHub
 (6 commenti) (1 reazione) (0 assegnatari)TypeScript (150 fork)auto 404
bughelp wanted

Metriche repository

Star
 (1798 star)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

Problem

Variables created with Pug/Svelte mixin (i.e. +each('links as link')) are not recognized by Typescript analyzer and cause "Cannot find name 'link'. Did you mean 'links'?" error.

Imgur

Example code:

<template lang="pug">
ul.nav
  +each('links as link')
    li(class:active="{ link.active }")
      a(href!="{ link.link }") { link.title }
</template>

<script lang="ts">
interface Link {
  active: boolean 
  link: string
  title: string
}

let links: Link[] = [
  { active: false, link: '#', title: 'Test Link 1' }, 
  { active: false, link: '#', title: 'Test Link 2' }, 
  { active: false, link: '#', title: 'Test Link 3' }, 
]
</script>

Context

Editor: VS Code or NVim Used preprocessors: Typescript, Pug, Sass. svelte-preprocess version: 4.0.9

Guida contributor