Skip to content

Comparison targets are reversed (regression) #30118

Closed as not planned
Closed as not planned

Description

Ryan Cavanaugh (@RyanCavanaugh) Wesley Wigham (@weswigham) Anders Hejlsberg (@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:

Activity

  1. RyanCavanaugh commented on Feb 27, 2019

    @RyanCavanaugh
    Member

    falsandtru (@falsandtru) please provide a reduced repro - thanks!

  2. jack-williams commented on Feb 27, 2019

    @jack-williams
    Collaborator

    falsandtru (@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
  3. falsandtru commented on Feb 27, 2019

    @falsandtru
    ContributorAuthor

    Ryan Cavanaugh (@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 (@jack-williams) No. The type parameters in your repro are not reversed.

  4. jack-williams commented on Feb 27, 2019

    @jack-williams
    Collaborator

    falsandtru (@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);
        }
    }
  5. falsandtru commented on Feb 27, 2019

    @falsandtru
    ContributorAuthor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Needs InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions