Skip to content

Intersection of mapped type of with omit not compatibleΒ #51972

Closed
@robinchrist

Description

@robinchrist

Bug Report

πŸ”Ž Search Terms

omit, mapped type, intersection

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, 3.5.1 up to 4.9.4

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type Column = {value: number}


type RemoveTitles<Type> = {
  [Property in keyof Type]: Omit<Type[Property], 'title'>;
};

class TableDataGenerator2<
  TIn extends { [colName: string]: Column & { title: string } },
  TAdd extends { [colName: string]: Column & { title: string } } = {}
> {

  constructor(
    private callback: (
      index: number,
      row: RemoveTitles<TIn>
    ) => Promise<RemoveTitles<TAdd>>
  ) {}

  chain<TAdd2 extends { [colName: string]: Column & { title: string } }>(
    cb: (
      index: number,
      row: RemoveTitles<TIn> & RemoveTitles<TAdd>
    ) => Promise<RemoveTitles<TAdd2>>
  ): TableDataGenerator2<TIn, TAdd & TAdd2> {
    return new TableDataGenerator2<TIn, TAdd & TAdd2>(async (index, input) => {
      const elem = await this.callback(index, input);
      const elem2 = await cb(index, { ...elem, ...input });
      return { ...elem2, ...elem };
    });
  }
}
Argument of type '(index: number, input: RemoveTitles<TIn>) => Promise<RemoveTitles<TAdd2> & RemoveTitles<TAdd>>' is not assignable to parameter of type '(index: number, row: RemoveTitles<TIn>) => Promise<RemoveTitles<TAdd & TAdd2>>'.
  Type 'Promise<RemoveTitles<TAdd2> & RemoveTitles<TAdd>>' is not assignable to type 'Promise<RemoveTitles<TAdd & TAdd2>>'.
    Type 'RemoveTitles<TAdd2> & RemoveTitles<TAdd>' is not assignable to type 'RemoveTitles<TAdd & TAdd2>'.

πŸ™ Actual behavior

TypeScript does not detect that RemoveTitles<T1> & RemoveTitles<T2> is compatible with RemoveTitles<T1 & T2>

πŸ™‚ Expected behavior

RemoveTitles<T1> & RemoveTitles<T2> is compatible with RemoveTitles<T1 & T2> and should be treated as equivalent, as can be seen in this example

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions