microsoft / microsoft/TypeScript

Mapped types shouldn't transform unknown type

Open
#29,793 5 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

@ahejlsberg Probably #29740 made this regression.

TypeScript Version: 3.4.0-dev.20190207

Search Terms:

Code

type DeepReadonly<T> =
  T extends void ? T :
  { readonly [P in keyof T]: DeepReadonly<T[P]>; };
type m = { a: unknown }; // Also unknown[].
type i = DeepReadonly<m>;

Expected behavior:

i is { readonly a: unknown; }.

Actual behavior:

i is { readonly a: {}; }.

Playground Link:

Related Issues:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the provided DeepReadonly snippet with TypeScript 3.4.0-dev.20190207 and compare the mapped result for unknown with the expected type. Trace the mapped-type and unknown-type handling; done means unknown remains unknown, including the noted unknown[] case, rather than becoming {}.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.