You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You have a comment in the 14.5-literal-inference.explainer.ts file:
// When returning the value only, it infers// the literal typeconstreturnsValueOnly=<T>(t: T)=>{returnt;};constresult=returnsValueOnly("a");// ^?
This explanation is a bit misleading. In your example, it returns literal type not because of how your function is declared but because of how it is called. In other words, it is returned literal because "a" parameter is interpreted as literal.
For example, if you pre-declare the function's argument as let the type of return value will be a string:
The text was updated successfully, but these errors were encountered:
You have a comment in the 14.5-literal-inference.explainer.ts file:
This explanation is a bit misleading. In your example, it returns literal type not because of how your function is declared but because of how it is called. In other words, it is returned literal because
"a"
parameter is interpreted as literal.For example, if you pre-declare the function's argument as
let
the type of return value will be astring
:The text was updated successfully, but these errors were encountered: