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

Wrong no-unsafe-member-access for reactive assignments and store subscriptions #89

Open
dummdidumm opened this issue Feb 18, 2021 · 7 comments
Labels
enhancement New feature or request

Comments

@dummdidumm
Copy link
Member

#87 uncovered some limitations when using type-aware rules. Some of these are fixed by #88 , but not all of them. Reactive assignments and store subscriptions will fail:

<script lang="ts">
  import { writable } from 'svelte/store';
  const store = writable([]);
  $store.length; // wrong no-unsafe-member-access error
  $: assignment = [];
  assignment.length; // wrong no-unsafe-member-access error
  // You can work around this by doing
  let another_assignment: string[];
  $: another_assignment = [];
  another_assignment.length; // OK
</script>

This is because the transformation just prepends generated let X statements above the code, with no specific type set to it. For it to work correctly, we would need to do transformations inline:

  • $: assignment = .. --> let assignment = .. (but only if user did not declare the let himself)
  • const store = writable(...) --> const store = writable(..);let $store = get_store_value(store) (where get_store_value is a fake function returning the Value in Store<Value>)

This would be similar to how we transform code in svelte2tsx for the intellisense features. The hard part is getting the line mappings correctly afterwards.

@Conduitry Conduitry added the enhancement New feature or request label Mar 8, 2021
@mohe2015
Copy link

Sorry to bump this but this is pretty annoying as stores are quite a core feature of svelte. Is there any workaround except for adding ignore directives?

@dummdidumm
Copy link
Member Author

This should be fixed for stores, for reactive statements it's not working yet.

@DetachHead
Copy link

is this the same issue?

<script lang="ts">
    $: foo = 1
    foo.toString // no error
    const bar = () => {
        foo.toString // @typescript-eslint/no-unsafe-member-access
    }
</script>

@locmark
Copy link

locmark commented Nov 29, 2022

is this the same issue?

<script lang="ts">
    $: foo = 1
    foo.toString // no error
    const bar = () => {
        foo.toString // @typescript-eslint/no-unsafe-member-access
    }
</script>

any updates on that? It's super annoying..

@wtachau
Copy link

wtachau commented May 4, 2023

any update?

@mohe2015
Copy link

mohe2015 commented May 4, 2023

The README of this project says it got replaced. Idk if that helps though

@wtachau
Copy link

wtachau commented May 4, 2023

Just noticed that :-/. I updated to eslint-plugin-svelte, which seems like it mostly works, though now I have to change some other configs. (For any future curious readers, I'm looking at https://github.com/sveltejs/eslint-plugin-svelte#parser-configuration and sveltejs/language-tools#650)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants