Skip to content

Function: As() ​

As<T>(inp): T

Cast a value to a type, for the type checker only: the value is returned as it is, neither converted nor checked at run time (a string cast to number stays a string).

Type Parameters ​

T ​

T = any

Parameters ​

inp ​

any

The value to cast, of any type.

Returns ​

T

The same value, typed as T.

Example ​

typescript
import {As} from 'lakutata/utils'

const payload: unknown = JSON.parse('{"id": 7}')
const order: {id: number} = As<{id: number}>(payload)
console.log(order.id)
//7

Released under the MIT License.