// RUNTIME VALIDATORS
export function is < T > ( input : unknown ) : input is T ; // returns boolean
export function assert < T > ( input : unknown ) : T ; // throws TypeGuardError
export function assertGuard < T > ( input : unknown ) : asserts input is T ;
export function validate < T > ( input : unknown ) : IValidation < T > ; // detailed
// JSON FUNCTIONS
export namespace json {
export function application < T > ( ) : IJsonApplication ; // JSON schema
export function assertParse < T > ( input : string ) : T ; // type safe parser
export function assertStringify < T > ( input : T ) : string ; // safe and faster
}
// LLM FUNCTION CALLING SCHEMA
export namespace llm {
// application schema from a class or interface type
export function application < App , Model > ( ) : ILlmApplication < Model > ;
// structured output
export function parameters < P , Moodel > ( ) : ILlmSchema . IParameters < Model > ;
export function schema < T , Model > ( ) : ILlmSchema < Model > ; // type schema
}
// PROTOCOL BUFFER
export namespace protobuf {
export function message < T > ( ) : string ; // Protocol Buffer message
export function assertDecode < T > ( buffer : Uint8Array ) : T ; // safe decoder
export function assertEncode < T > ( input : T ) : Uint8Array ; // safe encoder
}
// RANDOM GENERATOR
export function random < T > ( g ?: Partial < IRandomGenerator > ) : T ; typia เป็นห้องสมุดหม้อแปลงที่รองรับคุณสมบัติด้านล่าง:
บันทึก
class-validator 20,000 เท่าclass-transformer 200x หากคุณเรียกฟังก์ชั่น typia มันจะถูกรวบรวมเช่นด้านล่าง
นี่คือแนวคิดหลักของ typia การแปลงประเภท typeycript เป็นฟังก์ชันรันไทม์ ฟังก์ชั่น typia.is<T>() ถูกแปลงเป็นตัวตรวจสอบประเภทเฉพาะโดยการวิเคราะห์ประเภทเป้าหมาย T ในระดับการรวบรวม
คุณลักษณะนี้ช่วยให้นักพัฒนาสามารถสร้างความปลอดภัยให้กับประเภทในแอปพลิเคชันของพวกเขาใช้ประโยชน์จากการพิมพ์แบบคงที่ของ TypeScript ในขณะเดียวกันก็ให้การตรวจสอบความถูกต้องของรันไทม์ แทนที่จะกำหนด schemas เพิ่มเติมคุณสามารถใช้ประเภท typescript บริสุทธิ์ได้เอง
//----
// examples/checkString.ts
//----
import typia , { tags } from "typia" ;
export const checkString = typia . createIs < string > ( ) ;
//----
// examples/checkUUID.js
//----
import typia from "typia" ;
export const checkString = ( ( ) => {
return ( input ) => "string" === typeof input ;
} ) ( ) ; ขอบคุณสำหรับการสนับสนุนของคุณ
การบริจาคของคุณสนับสนุนการพัฒนา typia
นอกจากนี้ typia ยังแจกจ่ายครึ่งหนึ่งของการบริจาคให้กับผู้มีส่วนร่วมหลักของ typia
nonara/ts-patchryoppippi/unplugin-typiaคุณจะได้สัมผัสกับวิธีการทำงานของ Typia โดยเว็บไซต์ Playground:
ตรวจสอบเอกสารในเว็บไซต์:
assert() ฟังก์ชั่นis() ฟังก์ชั่นvalidate() ฟังก์ชั่นstringify() ฟังก์ชั่นparse() ฟังก์ชั่นapplication() ฟังก์ชั่นparameters()schema()decode()encode() ฟังก์ชั่นdev.to บทความ