Skip to content

Types: Reactive fields are always any #360

@AlexAegis

Description

@AlexAegis

Reactive fields (If thats that fields marked with $: are) are always any And this causes problems with noImplicitAny (And with regular intellisense)

tsconfig.json

{
	"compilerOptions": {
		"noImplicitAny": true,
	}
}

app.svelte

<script lang="ts">
	let value = 1;
	$: foo = value ? 'foo' : 'bar'; // foo is `any` here instead of the correct `string`
</script>

{#if value}{foo}{/if}
app.svelte:3:1
Error: Variable 'foo' implicitly has type 'any' in some locations where its type cannot be determined. (ts)
alue = 1;
        $: foo = 

app.svelte:6:13
Error: Variable 'foo' implicitly has an 'any' type. (ts)
if value}{foo}{/if}

Interestingly enough, any other reference made from the reactive field have a correct type again.

So this:

app2.svelte

<script lang="ts">
	let value = 1;
	$: foo = value ? 'foo' : 'bar';
	let bar = foo;
</script>

{#if value}{bar}{/if}

Works! Svelte-check does not output any errors. (But it's not reactive)

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedFixed in master branch. Pending production release.feature requestNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions