Skip to content

bug: operations failed unless separated #16244

Description

@KiaraGrouwstra

TypeScript Version: 2.3.1-insiders.20170416 (Playground, strictNullChecks off)

Code

Omit type for #12215:

// helpers...typeObj<T>={[k: string]: T};typeSafeObj<Oextends{[k: string]: any},Nameextendsstring,Paramextendsstring>=O&Obj<{[KinName]: Param}>;typeSwitchObj<Paramextendsstring,Nameextendsstring,OextendsObj<any>>=SafeObj<O,Name,Param>[Param];typeNot<Textendsstring>=SwitchObj<T,'InvalidNotParam',{'1': '0';'0': '1';}>;typeUnionHas<Unionextendsstring,Kextendsstring>=({[SinUnion]: '1'}&{[k: string]: '0'})[K];typeObj2Keys<T>={[KinkeyofT]: K}&{[k: string]: undefined};// data...typeItem1={a: string,b: number,c: boolean};// okay, Omit, let's go.typeOmit_<Textends{[s: string]: any},KextendskeyofT>={[P2inkeyofT]: {1: Obj2Keys<T>[P2],0: undefined}[Not<UnionHas<K,P2>>]}typeT1=Omit_<Item1,"a">;// intermediary result: { a: undefined; b: "b"; c: "c"; }typeT2={[P1inT1[keyofItem1]]: Item1[P1]};// { b: number, c: boolean };// ^ great, the result we want!// now let's combine the steps?!typeOmit<Textends{[s: string]: any},KextendskeyofT>={[P1in{[P2inkeyofT]: {1: Obj2Keys<T>[P2],0: undefined}[Not<UnionHas<K,P2>>]}[keyofT]]: T[P1]};typeT3=Omit<Item1,"a">;// ^ yields { a: string, b: number, c: boolean }, not { b: number, c: boolean }// uh, could we instead do the next step in a separate wrapper type?:typeOmit2<Textends{[s: string]: any},KextendskeyofT>=Omit_<T,K>[keyofT];// ^ not complete yet, but this is the minimum repro of the part that's going wrongtypeT4=Omit2<Item1,"a">;// ^ nope, foiled again! 'a'|'b'|'c' instead of 'b'|'c'... wth? // fails unless this access step is done after the result is calculated, dunno why

Similar issue encountered in my attempt to calculate union differences to resolve #13470.

Expected behavior:
Operations can be combined so as to make more sophisticated types.

Actual behavior:
The compiler gets confused if the access step directly follows the previous half of the computation.

Edit: it appears #16018 is closer to a minimum repro of this same issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions