@@ -13,6 +13,15 @@ expectType<Set<{'foo-bar': string}>>(bar);
1313declare const withOptions : DelimiterCasedPropertiesDeep < Set < { helloWorld : { p2p : Array < { addressLine1 : string } > } } > , '.' , { splitOnNumbers : true } > ;
1414expectType < Set < { 'hello.world' : { 'p.2.p' : Array < { 'address.line.1' : string } > } } > > ( withOptions ) ;
1515
16+ declare const withPunctuation : DelimiterCasedPropertiesDeep < { 'hello@World1' : { 'foo::Bar' : string } } , '.' > ;
17+ expectType < { 'hello@.world1' : { 'foo::.bar' : string } } > ( withPunctuation ) ;
18+
19+ declare const withPunctuationSplit : DelimiterCasedPropertiesDeep < { 'hello@World1' : { 'foo::Bar' : string } } , '.' , { splitOnPunctuation : true } > ;
20+ expectType < { 'hello.world1' : { 'foo.bar' : string } } > ( withPunctuationSplit ) ;
21+
22+ declare const withPunctuationSplitAndNumbers : DelimiterCasedPropertiesDeep < { 'hello@World1' : { 'foo::Bar1' : string } } , '.' , { splitOnPunctuation : true ; splitOnNumbers : true } > ;
23+ expectType < { 'hello.world.1' : { 'foo.bar.1' : string } } > ( withPunctuationSplitAndNumbers ) ;
24+
1625// Verify example
1726type User = {
1827 userId : number ;
@@ -26,6 +35,18 @@ type UserWithFriends = {
2635 userFriends : User [ ] ;
2736} ;
2837
38+ type UserPunctuated = {
39+ 'user::id' : number ;
40+ 'user::name' : string ;
41+ date : Date ;
42+ 'reg::exp' : RegExp ;
43+ } ;
44+
45+ type UserWithFriendsPunctuated = {
46+ 'user@info' : UserPunctuated ;
47+ 'user#friends' : UserPunctuated [ ] ;
48+ } ;
49+
2950const result : DelimiterCasedPropertiesDeep < UserWithFriends , '-' > = {
3051 'user-info' : {
3152 'user-id' : 1 ,
@@ -49,6 +70,7 @@ const result: DelimiterCasedPropertiesDeep<UserWithFriends, '-'> = {
4970 ] ,
5071} ;
5172expectType < DelimiterCasedPropertiesDeep < UserWithFriends , '-' > > ( result ) ;
73+ expectType < DelimiterCasedPropertiesDeep < UserWithFriendsPunctuated , '-' , { splitOnPunctuation : true } > > ( result ) ;
5274
5375// Test object key properties
5476declare const key : DelimiterCasedPropertiesDeep < { readonly userId ?: number } , '-' > ;
@@ -89,3 +111,6 @@ expectType<{'foo_bar': {'bar_baz': unknown}; biz: unknown}>({} as DelimiterCased
89111
90112expectType < { 'foo-bar' : any } > ( { } as DelimiterCasedPropertiesDeep < { fooBar : any } , '-' > ) ;
91113expectType < { 'foo_bar' : { 'bar_baz' : any } ; biz : any } > ( { } as DelimiterCasedPropertiesDeep < { fooBar : { barBaz : any } ; biz : any } , '_' > ) ;
114+
115+ expectType < { 'foo-bar' : unknown } > ( { } as DelimiterCasedPropertiesDeep < { 'foo::bar' : unknown } , '-' , { splitOnPunctuation : true } > ) ;
116+ expectType < { 'foo_bar' : { 'bar_baz' : unknown } ; biz : unknown } > ( { } as DelimiterCasedPropertiesDeep < { 'foo::bar' : { 'bar@baz' : unknown } ; biz : unknown } , '_' , { splitOnPunctuation : true } > ) ;
0 commit comments