Skip to content

Generic mapped as clause regression in 4.7Β #49541

Closed
@samhh

Description

@samhh

Bug Report

πŸ”Ž Search Terms

mapped, generic, as clause

πŸ•— Version & Regression Information

  • This changed between versions 4.6.4 and 4.7.2/4.7.3

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

The issue goes away if you remove the as Id<A> in Obj.

type Id<A> = A;

type Obj<A extends string> = {
  [K in A as Id<A>]: null
}

declare const getObj: <A extends string>() => Obj<A>

const f = <A extends 'a'>(): null => {
  const o = getObj<A>()
  return o['a' as A]
}

πŸ™ Actual behavior

1. Type 'Obj<A>[A]' is not assignable to type 'null'.
     Type 'Obj<A>["a"]' is not assignable to type 'null'.

πŸ™‚ Expected behavior

The compiler used to resolve o['a' as A] as null.

Metadata

Metadata

Assignees

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