How can I use branch code based on TypeScript types in Svelte?

Similar to Typescript: How to branch based on type but this is using Svelte, I am already using run-time type guards per that answer, and Svelte is still throwing errors. I have an array named collectablesInFolders, of type Collectable | Folder. Folders have a folderName property. Collectables don’t have a folderName. I have a runtime… Read More How can I use branch code based on TypeScript types in Svelte?

How define an optional prop in svelte with typescript?

I want to declare an optional prop in svelte with typescript, but I get the following error: "Declaration or statement expected". How can I declare the prop correctly? My Type export enum MyVariants { one = ‘one’, two = ‘two’ } Svelte component <script lang="ts"> export let variant?: MyVariants; </script> Error: ts Declaration or statement… Read More How define an optional prop in svelte with typescript?

How to prevent parent element from executing click code when checkbox is clicked in SvelteJS?

Problem In a SvelteJS project, I have a parent component that executes its own click code when the user clicks on it. I also have a child component that is an <input> element of type="checkbox". When the user clicks on the checkbox, the parent element executes its own click code as well. However, I want… Read More How to prevent parent element from executing click code when checkbox is clicked in SvelteJS?

How to access properties on a dynamically created component in Svelte

How can I access a component’s properties when that component was created dynamically at runtime? When creating a component in markup I can simply bind:someProperty={someVariable}, but I don’t know of any way to do this when the component is instantiated using new Component() at runtime? How can I get access to this new component’s properties?… Read More How to access properties on a dynamically created component in Svelte

Svelte reactive statement not triggering, when variable updated asynchronously in another file

A reactive statement isn’t triggering how I expect, in this toy example. I’m updating a variable x in a separate file, and I’d expect this update to trigger a reactive statement in my main app, but it doesn’t. When I use the same logic inside my main app, for variable y, it does trigger the… Read More Svelte reactive statement not triggering, when variable updated asynchronously in another file