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

Types: Reactive fields are always any #360

Closed
AlexAegis opened this issue Jul 25, 2020 · 1 comment
Closed

Types: Reactive fields are always any #360

AlexAegis opened this issue Jul 25, 2020 · 1 comment
Labels
feature request New feature or request Fixed Fixed in master branch. Pending production release.

Comments

@AlexAegis
Copy link

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)

@AlexAegis AlexAegis added the bug Something isn't working label Jul 25, 2020
@AlexAegis AlexAegis changed the title Reactive fields are always any Types: Reactive fields are always any Jul 25, 2020
@dummdidumm dummdidumm added feature request New feature or request and removed bug Something isn't working labels Jul 25, 2020
@dummdidumm
Copy link
Member

At the moment this is known and intended, but there is a pending PR which will resolve this (#335)

@dummdidumm dummdidumm added the Fixed Fixed in master branch. Pending production release. label Jul 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request Fixed Fixed in master branch. Pending production release.
Projects
None yet
Development

No branches or pull requests

2 participants