sveltejs/svelte-preprocess

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

Open

#207 opened on Jul 31, 2020

View on GitHub
 (6 comments) (1 reaction) (0 assignees)TypeScript (150 forks)auto 404
bughelp wanted

Repository metrics

Stars
 (1,798 stars)
PR merge metrics
 (PR metrics pending)

Description

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

Contributor guide