Back to Type Challenges

README

questions/16259-medium-to-primitive/README.md

latest1.5 KB
Original Source
<!--info-header-start--><h1>ToPrimitive </h1><blockquote><p>by 前端子鱼 <a href="https://github.com/mwc" target="_blank">@mwc</a></p></blockquote><p><a href="https://tsch.js.org/16259/play" target="_blank"></a> &nbsp;&nbsp;&nbsp;<a href="./README.zh-CN.md" target="_blank"></a> </p><!--info-header-end-->

Convert a property of type literal (label type) to a primitive type.

For example

typescript
type X = {
  name: 'Tom',
  age: 30,
  married: false,
  addr: {
    home: '123456',
    phone: '13111111111'
  }
}

type Expected = {
  name: string,
  age: number,
  married: boolean,
  addr: {
    home: string,
    phone: string
  }
}
type Todo = ToPrimitive<X> // should be same as `Expected`
<!--info-footer-start-->

<a href="../../README.md" target="_blank"></a> <a href="https://tsch.js.org/16259/answer" target="_blank"></a> <a href="https://tsch.js.org/16259/solutions" target="_blank"></a> <!--info-footer-end-->