| 1 | import {expectType} from 'tsd'; |
| 2 | import type {DelimiterCasedProperties} from '../index.d.ts'; |
| 3 | |
| 4 | declare const foo: DelimiterCasedProperties<{helloWorld: {fooBar: string}}, '/'>; |
| 5 | expectType<{'hello/world': {fooBar: string}}>(foo); |
| 6 | |
| 7 | declare const bar: DelimiterCasedProperties<Array<{helloWorld: string}>, '-'>; |
| 8 | expectType<Array<{helloWorld: string}>>(bar); |
| 9 | |
| 10 | declare const fooBar: DelimiterCasedProperties<() => {a: string}, '-'>; |
| 11 | expectType<() => {a: string}>(fooBar); |
| 12 | |
| 13 | declare const withOptions: DelimiterCasedProperties<{helloWorld1: {fooBar: string}}, '.', {splitOnNumbers: true}>; |
| 14 | expectType<{'hello.world.1': {fooBar: string}}>(withOptions); |
| 15 | |
| 16 | declare const withPunctuation: DelimiterCasedProperties<{'hello@World1': {'foo::Bar': string}}, '.'>; |
| 17 | expectType<{'[email protected]': {'foo::Bar': string}}>(withPunctuation); |
| 18 | |
| 19 | declare const withPunctuationSplit: DelimiterCasedProperties<{'hello@World1': {'foo::Bar': string}}, '.', {splitOnPunctuation: true}>; |
| 20 | expectType<{'hello.world1': {'foo::Bar': string}}>(withPunctuationSplit); |
| 21 | |
| 22 | declare const withPunctuationSplitAndNumbers: DelimiterCasedProperties<{'hello@World1': {'foo::Bar': string}}, '.', {splitOnPunctuation: true; splitOnNumbers: true}>; |
| 23 | expectType<{'hello.world.1': {'foo::Bar': string}}>(withPunctuationSplitAndNumbers); |
| 24 | |
| 25 | // Verify example |
| 26 | type User = { |
| 27 | userId: number; |
| 28 | userName: string; |
| 29 | }; |
| 30 | |
| 31 | type UserPunctuated = { |
| 32 | 'user::Id': number; |
| 33 | 'user::Name': string; |
| 34 | }; |
| 35 | |
| 36 | const result: DelimiterCasedProperties<User, '-'> = { |
| 37 | 'user-id': 1, |
| 38 | 'user-name': 'Tom', |
| 39 | }; |
| 40 | expectType<DelimiterCasedProperties<User, '-'>>(result); |
| 41 | expectType<DelimiterCasedProperties<UserPunctuated, '-', {splitOnPunctuation: true}>>(result); |