Giter Club home page Giter Club logo

Comments (6)

smalluban avatar smalluban commented on September 26, 2024 1

Thanks for clarification. Feel free to re-open if you think we can do something with it.

from hybrids.

Qsppl avatar Qsppl commented on September 26, 2024

First error:

You broke the Component<CustomElement> type by mapping in your interface:

image

Let's fix this:

image

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.
image
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.

Qsppl avatar Qsppl commented on September 26, 2024

Sent a bug report: microsoft/TypeScript#58016

from hybrids.

Qsppl avatar Qsppl commented on September 26, 2024

Typescript contributors say that this problem will not be solved in the near future, so we are solving it ourselves.

from hybrids.

smalluban avatar smalluban commented on September 26, 2024

Do you have a solution, which might be implemented on our side? If not, I would close the issue.

from hybrids.

Qsppl avatar Qsppl commented on September 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.