Giter Club home page Giter Club logo

Comments (9)

vilicvane avatar vilicvane commented on June 8, 2024 1

Consider this:

interface Foo {
  name: string;
  id: string;
  foo: boolean;
}

interface Bar {
  name: string;
  id: string;
  bar: number;
}

type FooBar = Omit<Foo | Bar, 'name'>;

let fooBar!: FooBar;

Without the conditional type (which wraps Pick), FooBar just picks the common part and downgrade the union type.

from utility-types.

piotrwitek avatar piotrwitek commented on June 8, 2024 1

Thanks for detailed explanation @vilic,
After some consideration that might be usefull, but it will require quite the effort as the change should be included in all relevant types to remain consistent and add new type test cases with unions input for each of the Type Operators.

I'll try to plan the milestone for it.

from utility-types.

piotrwitek avatar piotrwitek commented on June 8, 2024

What is it suppose to change in comparison to my current implementation? It's using conditional types already, have you checked it?

export type Omit<T, K extends keyof T> = Pick<T, SetComplement<keyof T, K>>;

from utility-types.

IssueHuntBot avatar IssueHuntBot commented on June 8, 2024

@BoostIO funded this issue with $10. Visit this issue on Issuehunt

from utility-types.

IssueHuntBot avatar IssueHuntBot commented on June 8, 2024

@issuehuntfest has funded $90.00 to this issue. See it on IssueHunt

from utility-types.

donabrams avatar donabrams commented on June 8, 2024

More info: https://gist.github.com/donabrams/b849927f5a0160081db913e3d52cc7b3

from utility-types.

piotrwitek avatar piotrwitek commented on June 8, 2024

I'm going to rollback the change from this proposal aiming to increase convenience for union types because it is breaking Generic Types support, which for me is more important to make it work (especially breaking in usage with Higher order components).

Consider these examples, which are all broken when Omit become distributive:

const fn = <T extends Props>(props: T) => {
    const { age, ...rest } = props;
    // @dts-jest:pass:snap
    const a: Omit<T, 'age'> = rest;
  };

const fn = <T extends Props>(props: T) => {
    const { age, ...rest } = props;
    // @dts-jest:pass:snap
    const a: Intersection<T, Omit<T, 'age'>> = rest;
  };

const fn = <T extends Props>(props: T) => {
    const { age, ...rest } = props;
    // @dts-jest:pass:snap
    const a: Overwrite<Omit<T, 'age'>, T> = rest;
  };

const fn = <T extends Props>(props: T) => {
    const { age, ...rest } = props;
    // @dts-jest:pass:snap
    const a: Assign<{}, Omit<T, 'age'>> = rest;
  };

from utility-types.

IssueHuntBot avatar IssueHuntBot commented on June 8, 2024

@piotrwitek has rewarded $70.00 to @piotrwitek. See it on IssueHunt

  • 💰 Total deposit: $100.00
  • 🎉 Repository reward(20%): $20.00
  • 🔧 Service fee(10%): $10.00

from utility-types.

piotrwitek avatar piotrwitek commented on June 8, 2024

Also, the previous Omit was not consistent with Pick and incompatible with build-in Omit coming in TypeScript v3.5.

Now it's fixed.

from utility-types.

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.