Skip to content

Commit 0352659

Browse files
committed
Updated types
1 parent 2e2f47f commit 0352659

File tree

6 files changed

+29
-16
lines changed

6 files changed

+29
-16
lines changed

src/dynamic-navigations.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { Type } from '@nestjs/common'
1+
import type { Type } from '@nestjs/common'
22

33
import { toCamelCase } from './helpers'
44

5+
import type { KeysMatching } from './types'
6+
57
let _navigations: INavigationMap[] | undefined
68

79
/**

src/dynamic-resolvers.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { GraphQLResolveInfo } from 'graphql'
1+
import type { GraphQLResolveInfo } from 'graphql'
22

33
import { Inject, Type } from '@nestjs/common'
44
import {
@@ -23,6 +23,8 @@ import {
2323
toCamelCase,
2424
} from './helpers'
2525

26+
import type { Dictionary } from './types'
27+
2628
let _resolverParams: IRegisterDynamicResolverParams[] | undefined
2729

2830
export interface IOnResolvingParams<P extends object = object, TRoot extends object = object> {

src/helpers/extract-grapql-selections.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { FieldNode, GraphQLResolveInfo, Kind } from 'graphql'
22

3+
import type { ObjectKeys, KeysMatching } from '../types'
4+
35
/**
46
* Defines how the fields should be renamed/mapped.
57
*

src/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import '../types'
2-
31
export * from './dynamic-navigations'
2+
43
export {
54
extractGraphQLSelectionPath,
65
extractGraphQLSelections,

types.d.ts renamed to src/types.ts

+16-11
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
1+
/**
2+
* The function interface.
3+
*/
4+
export type Func<A extends any[] = any[], R = any> = (...args: A) => R
5+
16
/**
27
* Gets the keys of type `T` matching the `V` values.
38
*/
4-
declare type KeysMatching<T, V> = { [ K in keyof T ]-?: T[ K ] extends V ? K : never }[ keyof T ]
9+
export type KeysMatching<T, V> = { [ K in keyof T ]-?: T[ K ] extends V ? K : never }[ keyof T ]
510

611
/**
712
* A Dictionary type for keeping `TValue` values.
813
*/
9-
declare type Dictionary<TValue> = { [ key: string ]: TValue }
14+
export type Dictionary<TValue> = { [ key: string ]: TValue }
1015

1116
/**
1217
* Maps the given type to its function keys.
1318
* If the given type is an array, then the function indices will be returned.
1419
* If the given type is an object, then the function keys will be returned.
1520
*/
16-
declare type FunctionKeys<T>
21+
export type FunctionKeys<T>
1722
= T extends any[]
1823
? Exclude<_FunctionKeys<T>, -1>
1924
: T extends { [ key: string ]: any }
@@ -23,43 +28,43 @@ declare type FunctionKeys<T>
2328
/**
2429
* Defines the nullable version of given type.
2530
*/
26-
declare type Nullable<T> = T | null | undefined
31+
export type Nullable<T> = T | null | undefined
2732

2833
/**
2934
* Defines the nullable version of given type with `void` type.
3035
*/
31-
declare type NullableReturn<T> = Nullable<T> | void
36+
export type NullableReturn<T> = Nullable<T> | void
3237

3338
/**
3439
* Defines a type which can be in a promise or not.
3540
*/
36-
declare type MaybePromise<T> = Promise<T> | T
41+
export type MaybePromise<T> = Promise<T> | T
3742

3843
/**
3944
* Gets the keys of an object whose values are objects.
4045
*
4146
* This does not include function keys.
4247
*/
43-
declare type ObjectKeys<T extends object>
48+
export type ObjectKeys<T extends object>
4449
= Exclude<KeysMatching<T, object>, FunctionKeys<T>>
4550

4651
/**
4752
* Gets the length of an array.
4853
*/
49-
declare type Length<T extends any[]> = T extends { length: infer L } ? L : never
54+
export type Length<T extends any[]> = T extends { length: infer L } ? L : never
5055

5156
/**
5257
* Builds a tuple with given length.
5358
*/
54-
declare type BuildTuple<L extends number, T extends any[] = []>
59+
export type BuildTuple<L extends number, T extends any[] = []>
5560
= T extends { length: L } ? T : BuildTuple<L, [ ...T, any ]>
5661

57-
type _FunctionKeys<TArray extends any[], CurrentIndex = 0, Index = -1>
62+
type _FunctionKeys<TArray extends any[], CurrentIndex extends number = 0, Index = -1>
5863
= TArray extends [ infer H, ...infer T ]
5964
? H extends Func
6065
? _FunctionKeys<T, Add<CurrentIndex, 1>, Index | CurrentIndex>
6166
: _FunctionKeys<T, Add<CurrentIndex, 1>, Index>
6267
: Index
6368

6469
type Add<A extends number, B extends number> =
65-
Length<[ ...BuildTuple<A>, ...BuildTuple<B> ]>
70+
Length<[ ...BuildTuple<A>, ...BuildTuple<B> ]> & number

tsconfig.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
"forceConsistentCasingInFileNames": true,
1717
"strict": true,
1818
"skipDefaultLibCheck": true,
19-
"skipLibCheck": true
19+
"skipLibCheck": true,
20+
"lib": [
21+
"ES2015"
22+
]
2023
},
2124
"exclude": [
2225
"node_modules",

0 commit comments

Comments
 (0)