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

transition directive doesn't accept undefined values with exactOptionalPropertyTypes enabled #6926

Closed
macmillen opened this issue Nov 13, 2021 · 4 comments · Fixed by #6927
Closed
Labels
runtime Changes relating to runtime APIs

Comments

@macmillen
Copy link
Contributor

Describe the problem

In TypeScript 4.4 the flag exactOptionalPropertyTypes was introduced which fixed some weak typing mechanics for the Partial<> utility type. When enabling this flag in a Svelte project it is throwing errors when passing undefined to transition directives.

<script lang="ts">
  import { crossfade } from "svelte/transition";

  // send and receive functions can be undefined
  const [send, receive] = crossfade({ duration: 400 });
</script>

<div
  in:receive={{ key }}
  out:send={{ key }}
/>

Describe the proposed solution

Make undefined a valid prop type for svelte transition directives.

Alternatives considered

Make the crossfade function not return possibly undefined values but maybe an empty function. (I think this would be a bad alternative though)

Importance

would make my life easier

@dummdidumm dummdidumm transferred this issue from sveltejs/svelte Nov 13, 2021
@dummdidumm dummdidumm transferred this issue from sveltejs/language-tools Nov 14, 2021
@dummdidumm dummdidumm added the runtime Changes relating to runtime APIs label Nov 14, 2021
@dummdidumm
Copy link
Member

I guess you mean noUncheckedIndexedAccess . We need to adjust the index signature so that it's a tuple, not an array.

dummdidumm added a commit that referenced this issue Nov 14, 2021
People with "noUncheckedIndexedAccess" set to true in their tsconfig would get false errors when accessing the return type because without this spefici tuple typing, TS infers this as being an array of functions, not a tuple of functions.
Fixes #6926
dummdidumm added a commit that referenced this issue Nov 14, 2021
People with "noUncheckedIndexedAccess" set to true in their tsconfig would get false errors when accessing the return type because without this specific tuple typing, TS infers the return type as being an array of functions, not a tuple of functions.
Fixes #6926
@macmillen
Copy link
Contributor Author

I think I got confused a bit about the actual problem and I thought the crossfade was related but it's nice that it's fixed anyway 😄

The actual feature request that I meant to describe was the following:

Imagine I have a component that can apply a transition conditionally like this:

<script lang="ts">
  type Transition = (node: Element, params: SvelteTransitionConfig) => SvelteTransitionReturnType;

  export let myTransition: Transition | undefined = undefined;
</script>

<div in:myTransition>
  <div>content</div>
</div>
<MyComponent
  myTransition={(node, params) => ({
    ...params,
    css: (t, u) => `transform: scale(${t}) translateY(${u * 4}px);`,
  })}
/>

Because sometimes I want the component to have a transition and sometimes not. My idea was to make the transition directive accept an undefined value to make that possible.

If you want I can create another GitHub Issue if that makes things easier for you. Anyhow thank you for looking into it @dummdidumm 🙏

@dummdidumm
Copy link
Member

I created #6942 for this.

@macmillen
Copy link
Contributor Author

awesome, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
runtime Changes relating to runtime APIs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants