2 ms·
Typescript’s type narrowing is useful for this exact situation: // v is any or unknown if (typeof v !== "string") { throw new Error("oops") } // v
by wruza 5y ago
Typescript’s type narrowing is useful for this exact situation:
// v is any or unknown
if (typeof v !== "string") {
throw new Error("oops")
}
// v is now string
You can’t get runtime type correctness by deceiving typescript into it.