Giter VIP home page Giter VIP logo

Comments (4)

MartinJohns avatar MartinJohns commented on May 2, 2024 2

Duplicate of #39600.

from typescript.

MartinJohns avatar MartinJohns commented on May 2, 2024 1

UnionToIntersection has been called an ill formed type by the team. It's not supported and it could stop working with any new version.

from typescript.

MartinJohns avatar MartinJohns commented on May 2, 2024
// I assumed the above solution is equal to overloading

That assumption is wrong. Keep in mind that E can be a union type as well. It's perfectly valid that the type for E is "invalidate" | "reassign". That also means it's possible to provide an invalid mesg for the event.

from typescript.

kalkronline avatar kalkronline commented on May 2, 2024

@MartinJohns Yes that is correct, I do account for this through these

// helper types
// https://stackoverflow.com/questions/50374908/transform-union-type-to-intersection-type
type UnionToIntersection<U> = 
	(U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never

// https://stackoverflow.com/questions/53953814/typescript-check-if-a-type-is-a-union
type IsUnion<T, U extends T = T> =
    (T extends any ?
    (U extends T ? false : true)
        : never) extends false ? false : true

export type OneOf<T, K> = IsUnion<K> extends false ? keyof T : never;

recv<E extends OneOf<Events, E>>(event: E, cb: (mesg: Events[E]>) => void) {}

I meant equal in the context of the problem, which is how they handle void.

from typescript.

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.