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: component not updated correctly HOT 3
- Svelte 5 onclick error when handler uses store subscription HOT 1
- Svelte 5: the new Bindable types completely destroyed my projects types. HOT 14
- Svelte 5: $state with computed properties + symbol (identifier) table HOT 7
- Svelte 5 bug - unexpected behaviour of Date from svelte/reactivity HOT 2
- Svelte 5: $bindable prop shouldn't update from within component if user has passed the prop but hasn't bind to it HOT 3
- Svelte 5: in & out transitions don't seem to run together
- [svelte 5]: `value` should be assigned and cleared here HOT 4
- [svelte 5]: stopPropagation works differently than v4 (non runes mode) HOT 2
- Svelte 5: Reactive elements not being updated
- Svelte 5: Crossfade playing fallback consistently in some scenarios HOT 3
- Svelte does not save the type of generic passed to <slot /> from custom array HOT 1
- Svelte 5: cannot combine `multiple` with `bind:this` on select element
- Svelte 5: the $sync rune HOT 16
- Svelte 4: Missing TS inference with <input> HOT 1
- Sveltekit Dependency Issue with Vercel HOT 2
- When I try to run the development server.. HOT 1
- Svelte 5: Provide metadata/events needed for devtools et al HOT 1
- Svelte 5: documentation? HOT 1
- Svelte 5: `vitest` + `jsdom` error: mount(...) is not available on the server HOT 2
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.