title: How to constrain a type to be literal meaning that the user must write "as const"
body: <p>I want to define a literal type that all users must write 'as const'</p>
  <pre><code>type foo= literalType //
  const num0:foo = 123 // error
  const num:foo = &lt;const&gt;123 //ok
  const str:foo = 'str' as const //ok
  const arr:foo = [1,2,3] as const //ok 
  const obj:foo = {name:'lili'} // error
  const obj1:foo = {name:'lili'} as cosnt // ok
  //...
  </code></pre>
  <p>demo2
  Constrain generics to be literals ,T in foo .</p>
  <pre><code>function foo&lt;T&gt;( obj:{literal:T} ){}
  foo({
  literal: &lt;const&gt;123 //ok
  })
  foo0({
  literal: [1,2,3] //error Because it's not literal
  })
  foo1({
  literal: &lt;const&gt; [1,2,3] //ok
  })
  foo2({
  literal: &lt;const&gt; {name:'li'} //ok
  })
  foo3({
  literal: {name:'li'} //error Because it's not literal
  })
  </code></pre>
  <p>How to do in TS ?</p>
  <p>After writing a component, a document is returned.  The user will see the default value, which should be literal</p>
  <p><a href="https://i.stack.imgur.com/AzVoq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AzVoq.png" alt="enter image description here" /></a></p>
  <p>Like this</p>
  <p><a href="https://i.stack.imgur.com/ZXguH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZXguH.png" alt="enter image description here" /></a></p>
  <p>not <a href="https://i.stack.imgur.com/YNbtK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YNbtK.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/4MpV7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4MpV7.png" alt="enter image description here" /></a></p>