Skip to content

Refinement requirements fails for interface fieldsΒ #49614

@pakoito

Description

@pakoito

Bug Report

πŸ”Ž Search Terms

Enum refinement, enum unification, enum constant,

πŸ•— Version & Regression Information

3.3 and up, as far back as I could test it

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

const enum ToRefine {
    One,
    Two
}

type Refine<R extends ToRefine> = R extends ToRefine.One ? number : R extends ToRefine.Two ? string : never;
type RefineAny = Refine<ToRefine>;

function refined(param: Refine<ToRefine.One>) {
    return param + 1;
}

function callRefined(value: RefineAny) {
   refined(value)
}


interface Container<R extends ToRefine> {
    option: Refine<R>
}
type ContainerAny = Container<ToRefine>;

function contained(param: Container<ToRefine.One>) {
    return param.option + 1;
}

function callContained(value: ContainerAny) {
   contained(value)
}

πŸ™ Actual behavior

callRefined fails to typecheck due to a type mismatch as expected

callContained passes the typechecker when it shouldn't

πŸ™‚ Expected behavior

Both callRefined and callContained should fail to typecheck

Metadata

Metadata

Assignees

Labels

Needs InvestigationThis issue needs a team member to investigate its status.RescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions