TIL you can emulate the as const
type suffix in JS with a helper function. (source)
/**
* Identity function. Coerces string/number literals to value-as-type.
* @template {string|number} T
* @param {T} v
* @return {T}
*/
function toConst(v) {
return v;
}
const five = toConst(5);
// --> Type shows up as 5 instead of "number"
Responses
See how to respond...
Respond via email
If you'd prefer to message me directly, send an email. If you'd also like your message to be visible on the site I can add it as a comment.
Reply via Email
Respond from another site
Responses are collected from posts on other sites. Have you posted somewhere that links to this page? If so, share the link!