Skip to content

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

Open
@dummdidumm

Description

@dummdidumm

#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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions