Skip to content

Commit

Permalink
DelimiterCasedPropertiesDeep: Don't recurse into intersection type …
Browse files Browse the repository at this point in the history
…that include primitive value (#789)
  • Loading branch information
Emiyaaaaa committed Jan 4, 2024
1 parent 0aec247 commit eb96609
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion source/delimiter-cased-properties-deep.d.ts
@@ -1,4 +1,5 @@
import type {DelimiterCase} from './delimiter-case';
import type {NonRecursiveType} from './internal';
import type {UnknownArray} from './unknown-array';

/**
Expand Down Expand Up @@ -48,7 +49,7 @@ const result: DelimiterCasedPropertiesDeep<UserWithFriends, '-'> = {
export type DelimiterCasedPropertiesDeep<
Value,
Delimiter extends string,
> = Value extends Function | Date | RegExp
> = Value extends NonRecursiveType
? Value
: Value extends UnknownArray
? DelimiterCasedPropertiesArrayDeep<Value, Delimiter>
Expand Down
7 changes: 6 additions & 1 deletion test-d/opaque.ts
@@ -1,5 +1,5 @@
import {expectAssignable, expectNotAssignable, expectNotType, expectType} from 'tsd';
import type {Opaque, UnwrapOpaque, Tagged, UnwrapTagged} from '../index';
import type {Opaque, UnwrapOpaque, Tagged, UnwrapTagged, SnakeCasedPropertiesDeep} from '../index';

type Value = Opaque<number, 'Value'>;

Expand Down Expand Up @@ -112,3 +112,8 @@ const unwrapped2 = 123 as PlainValueUnwrapTagged;

expectType<number>(unwrapped1);
expectType<number>(unwrapped2);

// Test for issue https://github.com/sindresorhus/type-fest/issues/643
type IdType = Opaque<number, 'test'>;
type TestSnakeObject = SnakeCasedPropertiesDeep<{testId: IdType}>;
expectType<TestSnakeObject>({test_id: 2 as IdType});

0 comments on commit eb96609

Please sign in to comment.