Back to Type Challenges

README

questions/30970-medium-shitariteraru/README.md

latest1.6 KB
Original Source
<!--info-header-start--><h1>IsFixedStringLiteralType </h1><blockquote><p>by 蛭子屋双六 <a href="https://github.com/sugoroku-y" target="_blank">@sugoroku-y</a></p></blockquote><p><a href="https://tsch.js.org/30970/play" target="_blank"></a> &nbsp;&nbsp;&nbsp;<a href="./README.ja.md" target="_blank"></a> </p><!--info-header-end-->

Sometimes you may want to determine whether a string literal is a definite type. For example, when you want to check whether the type specified as a class identifier is a fixed string literal type.

typescript
type Action<ID extends string> = { readonly id: ID };

Since it must be fixed, the following types must be determined as false.

  • never type
  • Union of string literal types
  • Template literal types with embedded string, number, bigint, boolean

Determine whether the given type S is a definite string literal type.

<!--info-footer-start-->

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