4

I am practicing with the type, and then encountered this kind of problem, I read some posts and still can’t figure it out why.

type A = (() => true) extends Record<string, any> ? true : false; // => true
type B = (() => true) extends Record<string, unknown> ? true : false; // false
Yunfei He
  • 41
  • 3

1 Answers1

0

The basic difference between any and unknown is the way we assign it into other variables. unknown is type-safe, so it is impossible when you assign a variable with unkown to other variables with a specific type.

I think you can read more about these two posts.

  1. 'unknown' vs. 'any'
  2. https://mariusschulz.com/blog/the-unknown-type-in-typescript
Hung Du
  • 124
  • 1
  • 4
  • 1
    This answer doesn't explain why an arrow function *is a* `Record` but *is not a* `Record`. – VLAZ Dec 01 '20 at 11:32