Skip to content

Comparison targets are reversed (regression) #30118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
falsandtru opened this issue Feb 27, 2019 · 5 comments
Open

Comparison targets are reversed (regression) #30118

falsandtru opened this issue Feb 27, 2019 · 5 comments
Assignees
Labels
Needs Investigation This issue needs a team member to investigate its status.

Comments

@falsandtru
Copy link
Contributor

falsandtru commented Feb 27, 2019

@RyanCavanaugh @weswigham @ahejlsberg Caused by #27697

TypeScript Version: 3.4.0-dev.20190222

Search Terms:

Code

https://github.com/falsandtru/spica/blob/v0.0.237/src/supervisor.legacy.ts#L49

Expected behavior:

pass

Actual behavior:

Argument of type 'this' is not assignable to parameter of type 'Supervisor<string, unknown, unknown, unknown>'.
  Type 'Supervisor<N, P, R, S>' is not assignable to type 'Supervisor<string, unknown, unknown, unknown>'.
    Type 'string' is not assignable to type 'N'.ts(2345)

Assignability checking must be N to string, not reverse.

Playground Link:

Related Issues:

@RyanCavanaugh RyanCavanaugh added the Needs More Info The issue still hasn't been fully clarified label Feb 27, 2019
@RyanCavanaugh
Copy link
Member

@falsandtru please provide a reduced repro - thanks!

@jack-williams
Copy link
Collaborator

jack-williams commented Feb 27, 2019

@falsandtru Is this a repro?

interface Foo<T> {
    cast(name: ('' extends T ? string : string)): void;
}

interface Foo2<T> {
    cast(name: ('' extends T ? string : string)): void;
}

declare const y: Foo<string>;
const x: Foo<''> = y; // error

declare const y2: Foo2<string>;
const x2: Foo<''> = y2; // ok

@falsandtru
Copy link
Contributor Author

falsandtru commented Feb 27, 2019

@RyanCavanaugh Repro

export abstract class Supervisor<N extends string, P = unknown, R = unknown> {
  private static instances_: Set<Supervisor<string, unknown, unknown>>;
  private static get instances(): typeof Supervisor.instances_ {
    return this.hasOwnProperty('instances_')
      ? this.instances_
      : this.instances_ = new Set();
  }
  constructor() {
    void (this.constructor as typeof Supervisor).instances.add(this);
  }
  public abstract call(name: N | ('' extends N ? undefined : never), param: P, timeout?: number): Promise<R>;
}

@jack-williams No. The type parameters in your repro are not reversed.

@jack-williams
Copy link
Collaborator

jack-williams commented Feb 27, 2019

@falsandtru Yep, sorry. What about this?

class Foo<T extends string> {
    private static instance: Foo<string>[];

    cast(_name: ([T] extends [string] ? string : string)) {
        
    }
    
    foobar() {
        Foo.instance.push(this);
    }
}

@falsandtru
Copy link
Contributor Author

Looks like good except an illegal ! at the second line.

@RyanCavanaugh RyanCavanaugh removed the Needs More Info The issue still hasn't been fully clarified label Feb 28, 2019
@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Feb 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

No branches or pull requests

4 participants