Skip to content

Constraints applied by conditional types not considered when checking signatures #22347

Closed
@weswigham

Description

@weswigham

Code

declare function log(msg: string): void;
type EQString<T> = T extends string ? T : never;
function c<T>(x: T | string) {
    const y = x as EQString<T>; // assert stringiness
    return log(y);
}

Expected behavior:
No error.

Actual behavior:

[ts]
Argument of type 'EQString<T>' is not assignable to parameter of type 'string'.
  Type 'T' is not assignable to type 'string'

on y.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions