File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11{
22 "name" : " @gramio/callback-data" ,
3- "version" : " 0.0.8 " ,
3+ "version" : " 0.0.9 " ,
44 "main" : " dist/index.js" ,
55 "devDependencies" : {
66 "@biomejs/biome" : " ^1.9.4" ,
Original file line number Diff line number Diff line change @@ -316,3 +316,16 @@ export class CallbackData<
316316 return this as any ;
317317 }
318318}
319+
320+ export type InferDataPack < T extends CallbackData > = T extends CallbackData <
321+ infer SchemaType ,
322+ infer SchemaTypeInput
323+ >
324+ ? SchemaTypeInput
325+ : never ;
326+ export type InferDataUnpack < T extends CallbackData > = T extends CallbackData <
327+ infer SchemaType ,
328+ infer SchemaTypeInput
329+ >
330+ ? SchemaType
331+ : never ;
Original file line number Diff line number Diff line change 11import { expectTypeOf } from "expect-type" ;
2- import { CallbackData } from "../../src/index.ts" ;
2+ import {
3+ CallbackData ,
4+ type InferDataPack ,
5+ type InferDataUnpack ,
6+ } from "../../src/index.ts" ;
37
48const callbackDataString = new CallbackData ( "test" ) . string ( "name" , {
59 optional : true ,
@@ -118,3 +122,10 @@ const defaultUnpackedDataWithDefaults = defaultCallbackData.unpack(
118122expectTypeOf ( defaultUnpackedDataWithDefaults ) . toEqualTypeOf < {
119123 isActive : boolean ;
120124} > ( ) ;
125+
126+ {
127+ const cd = new CallbackData ( "test" ) . boolean ( "test" , { default : true } ) ;
128+
129+ expectTypeOf < InferDataPack < typeof cd > > ( ) . toEqualTypeOf < { test ?: boolean } > ( ) ;
130+ expectTypeOf < InferDataUnpack < typeof cd > > ( ) . toEqualTypeOf < { test : boolean } > ( ) ;
131+ }
You can’t perform that action at this time.
0 commit comments