question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

String content erased when inferring slot/event type from props

See original GitHub issue

The following Svelte code fails to check with svelte-check v2.2.3.

<!-- Component.svelte -->
<script lang="typescript">
  export let variant: "foo" | "bar"
  export let style: string
</script>
<!-- index.svelte -->
<script lang="typescript">
  import Component from "./Component.svelte";
</script>

<Component
  variant="foo"
  style={`${
    1
  }`}
  on:click={() => {}}
/>

It shows the error

Error: Type '""' is not assignable to type '"foo" | "bar"'. (ts)
  on:click={() => {}}
/>

The example looks artificial but this layout is produced by prettier if the expression inside ${} is long.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dummdidummcommented, Aug 24, 2021

The multiline problem is fixed now.

0reactions
jasonlyu123commented, Aug 2, 2021

The empty string part is released. You can try it again. I’ll leave this open for the multi-line problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Loss of function parameter typing when inferring props of ...
Tf you hover on exampleFunction to get the intellisense for it, the correct type is observed. It seems to be lost on the...
Read more >
Infer type from parent props - reactjs - Stack Overflow
Let me explain better with an example: suppose I have <Parent> and <Child> components, and an interface IMyComplexObject . interface ...
Read more >
Useful Patterns by Use Case - React TypeScript Cheatsheets
Strategy: extract a component's props by inferring them. Example: // ReactUtilityTypes.d.ts declare type $ElementProps<T> = T extends React.
Read more >
Notes on TypeScript: Inferring React PropTypes
In this part of the "Notes on TypeScript" we will learn how we can leverage TypeScript to infer these component prop-types.
Read more >
Notes on TypeScript: Inferring React PropTypes | by A. Sharif
When inferring these prop-type definitions, we can see that the returned type ... Type 'string' is not assignable to type 'number'
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found