cast
function cast<T>(value): T;Defined in: cast.ts:19
Return value typed as T. The same as value as T: an unchecked type
assertion with no runtime effect. As a function call it fits in expression
chains and is easy to search for.
Nothing is validated, so only use it when you know the shape. When the data might not match, use a schema or a type guard instead.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
unknown |
Returns
Section titled “Returns”T
Example
Section titled “Example”import { cast } from "@xtandard/lib";
type AppConfig = { port: number };
const config = cast<AppConfig>(JSON.parse('{"port":8080}'));config.port; // 8080 (config: AppConfig, not any)