Comments (6)
Thanks for clarification. Feel free to re-open if you think we can do something with it.
from hybrids.
First error:
You broke the Component<CustomElement>
type by mapping in your interface:
Let's fix this:
Now we have arrived at the same problem the right way
The factory(() => string)
function compares two types: Property<E, V = () => string>
and Property<E, V = string>
So let's simplify the task to...
type Property<T> =
| (T extends string | number | boolean | undefined ? T : never)
| ((lastValue: T) => T)
function factory<T>(value: Property<T>): Property<T> {
return value;
}
// Type 'string' is not assignable to type '() => string'.ts(2322)
factory(() => "")
type ExtractOrigin<P> = P extends Property<infer Origin> ? Origin : never;
type SecondGeneric = ExtractOrigin<() => string>
// We expect `string` but `string | (() => string)` comes back!
It looks like using type unions along with conditional types breaks typescript.
And your solution actually works for this case, although it looks absurd.
I assume that after the conditional type, all other elements of the type union break down.
Therefore, conditional types need to be moved to the end of type unions throughout the code. I found several more such cases in the /** Store **/
section.
from hybrids.
Sent a bug report: microsoft/TypeScript#58016
from hybrids.
Typescript contributors say that this problem will not be solved in the near future, so we are solving it ourselves.
from hybrids.
Do you have a solution, which might be implemented on our side? If not, I would close the issue.
from hybrids.
The solution proposed by @au-z only works because if you have several incompatible candidates for output, then the first one is selected as the assumed type.
This solution fixes the problem in this specific use case, but may create typing errors in other use cases.
Typescript contributors will not fix this issue.
To completely solve the problem, we need to change the types significantly.
You can put this problem aside for later, I can solve it when more problems related to types appear.
from hybrids.
Related Issues (20)
- Add a helper for assigning component properties HOT 3
- Dynamic columns not showing when render a html table HOT 4
- '"hybrids"' has no exported member named 'property'. Did you mean 'Property'? HOT 8
- Add support for "TypeScript v5" HOT 3
- I can't create an arbitrary number of nested forms: HOT 6
- Cannot pass an object to the API via the "list" method HOT 7
- version 8.2.17 backwards compatibility is broken! HOT 9
- Expand the functionality of drafts
- sync() with nested models is broken HOT 4
- Allow storing an object in a component property HOT 4
- Add partial loading of model data HOT 3
- Why do you remove the lastValue? HOT 2
- The store logs a lot of errors HOT 4
- Convert a Whole Component to Web Component HOT 8
- Scoped CSS HOT 6
- lagging update glitch HOT 2
- Component properties cannot be setted until they are observed HOT 2
- `store.set()` is very slow HOT 5
- Store loads items data when iterating the list of items 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 hybrids.