Comments (2)
Wonder if Svelte can do much here, these types don't really work.
If you union string
with 'string literal'
the result is always string
.
The if
type narrowing in the script block only works due to flow analysis, i.e. there is no code changing the variable before the if
, hence the type at that point is inferred to be that of the data provided in the declaration, rather than ServiceData
whose type
prop is useless.
E.g.
// no error
let sd: ServiceData = { type: 'nested_array', data: {} };
if (sd.type == 'nested_array') {
console.log(sd.data);
}
// error
function getData(): ServiceData {
return { type: 'nested_array', data: {} };
}
let sd2: ServiceData = getData();
if (sd2.type == 'nested_array') {
console.log(sd2.data);
}
from svelte.
As pointed out, the union type needs something to clearly discriminate against, and string
widens the type such that it no longer works. Closing as there's nothing Svelte can do
from svelte.
Related Issues (20)
- [Svelte 5] Regression in JS output - script context module variable declarations before import statements HOT 2
- [Svelte 5] Functions using `onMount` fail tests due no component initialization HOT 4
- Svelte 5: "ownership_invalid_binding" with arrays HOT 2
- [Feat] Pass a state/prop to function as getter/setter HOT 1
- [Svelte 5] False positive firefox ownership_invalid_mutation warning HOT 3
- Svelte 5: no warning/error on not-in-scope directive HOT 5
- $inspect destroying reactivity HOT 2
- Svelte 5: legacy mode wrong `export_let_unused` for `svelte:component` HOT 3
- `Component` type not working as expected HOT 1
- `@keyframes` in scoped style blocks do not work HOT 1
- `{@render children()}` crashes when importing WASM HOT 7
- Svelte 5: input bind:files has visually no two-way-binding HOT 5
- Ability to inject extra data to CSS class hashes to prevent CSS leaks HOT 5
- tag required in customElement options HOT 1
- Click on slot rendered content do not bubble events
- Imperatively controlling a component through $effect causes the effect to re-run indefinitely HOT 5
- [Svelte5] Unrelated state values are compiled into the same template effect when using class and the class:className directives. HOT 2
- Svelte 5 : `animate:flip` elements mispositioned after rapid state toggling HOT 1
- Svelte 5: reactivity inconsistent between state rune inside component and external HOT 2
- svelte.dev is not loading correctly in Nigeria unless VPN is used HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from svelte.