Skip to content

Commit c38923c

Browse files
authored
Merge pull request #295 from intercom/improve/typescript-3.x-compatibility
Simplify types to be compatible with TS v3.X
2 parents 8683a9e + c21d8e3 commit c38923c

File tree

4 files changed

+11
-62
lines changed

4 files changed

+11
-62
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ jobs:
1111
- run: export PATH="${PATH}:/home/circleci/.yarn/bin"
1212
- run: npm install --prefix=$HOME/.local --global corepack
1313
- run: yarn
14+
- run: yarn prepublish
1415
- run: yarn test
1516

1617
notify:

lib/common/common.types.ts

Lines changed: 6 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -24,56 +24,6 @@ export type Paginated<T> = {
2424
total_count: number;
2525
};
2626

27-
type Join<K, P> = K extends string | number
28-
? P extends string | number
29-
? `${K}${'' extends P ? '' : '.'}${P}`
30-
: never
31-
: never;
32-
33-
type Prev = [
34-
never,
35-
0,
36-
1,
37-
2,
38-
3,
39-
4,
40-
5,
41-
6,
42-
7,
43-
8,
44-
9,
45-
10,
46-
11,
47-
12,
48-
13,
49-
14,
50-
15,
51-
16,
52-
17,
53-
18,
54-
19,
55-
20,
56-
...0[]
57-
];
58-
59-
// D is depth, we don't want to go past 3 nested objects
60-
export type Paths<T, D extends number = 3> = [D] extends [never]
61-
? never
62-
: T extends object
63-
? {
64-
[K in keyof T]-?: K extends string | number
65-
? `${K}` | Join<K, Paths<T[K], Prev[D]>>
66-
: never;
67-
}[keyof T]
68-
: '';
69-
70-
// D is depth, we don't want to go past 3 nested objects
71-
export type Leaves<T, D extends number = 3> = [D] extends [never]
72-
? never
73-
: T extends object
74-
? { [K in keyof T]-?: Join<K, Leaves<T[K], Prev[D]>> }[keyof T]
75-
: '';
76-
7727
export enum Operators {
7828
AND = 'AND',
7929
OR = 'OR',
@@ -89,19 +39,19 @@ export enum Operators {
8939
ENDS_WITH = '$',
9040
}
9141

92-
interface FlatQuery<T> {
93-
field: Leaves<T>;
42+
interface FlatQuery {
43+
field: string;
9444
operator: Operators;
9545
value: string | number | null;
9646
}
9747

98-
interface NestedQueries<T> {
48+
interface NestedQueries {
9949
operator: Operators;
100-
value: Array<FlatQuery<T> | NestedQueries<T>> | string | number | null;
50+
value: Array<FlatQuery | NestedQueries> | string | number | null;
10151
}
10252

103-
export interface GenericSearchFilters<T> {
104-
query: FlatQuery<T> | NestedQueries<T>;
53+
export interface GenericSearchFilters {
54+
query: FlatQuery | NestedQueries;
10555
}
10656

10757
export enum Order {

lib/contact.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { ContactObject } from './contact/contact.types';
33
import {
44
GenericDeletedResponse,
55
GenericSearchFilters,
6-
Leaves,
76
Paginated,
87
Role,
98
} from './common/common.types';
@@ -287,13 +286,13 @@ interface SearchContactPagination {
287286

288287
interface SearchContactOrder {
289288
sort: {
290-
field: Leaves<ContactObject>;
289+
field: string;
291290
order: SearchContactOrderBy;
292291
};
293292
}
294293

295294
interface SearchContactRequest {
296-
data: GenericSearchFilters<ContactObject> &
295+
data: GenericSearchFilters &
297296
Partial<SearchContactPagination> &
298297
Partial<SearchContactOrder>;
299298
}

lib/conversation.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
Paginated,
44
StringifiedTimestamp,
55
GenericSearchFilters,
6-
Leaves,
76
Order,
87
} from './common/common.types';
98
import {
@@ -499,13 +498,13 @@ interface SearchConversationPagination {
499498

500499
interface SearchConversationOrder {
501500
sort: {
502-
field: Leaves<ConversationObject>;
501+
field: string;
503502
order: SearchConversationOrderBy;
504503
};
505504
}
506505

507506
interface SearchConversationRequest {
508-
data: GenericSearchFilters<ConversationObject> &
507+
data: GenericSearchFilters &
509508
Partial<SearchConversationPagination> &
510509
Partial<SearchConversationOrder>;
511510
}

0 commit comments

Comments
 (0)