Skip to content

Commit

Permalink
feat: update IsFunction types
Browse files Browse the repository at this point in the history
  • Loading branch information
unional committed Oct 4, 2023
1 parent dd3d5f8 commit 33c0208
Show file tree
Hide file tree
Showing 29 changed files with 563 additions and 609 deletions.
7 changes: 7 additions & 0 deletions .changeset/large-windows-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"type-plus": minor
---

Update `IsFunction`, `IsNotFunction`, `IsStrictFunction`, `IsNotStrictFunction`.

Remove `FunctionType`, `NotFunctionType`, `StrictFunctionType`, `NotStrictFunctionType`.
5 changes: 3 additions & 2 deletions type-plus/ts/bigint/is_not_strict_bigint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ it('can disable union distribution', () => {
testType.equal<IsNotStrictBigint<bigint | 1, { distributive: false }>, true>(true)
})

it('consider intersection type as not strict', () => {
testType.true<IsNotStrictBigint<bigint & { a: 1 }>>(true)
it('consider intersection type as strict', () => {
testType.false<IsNotStrictBigint<bigint & { a: 1 }>>(true)
testType.true<IsNotStrictBigint<1n & { a: 1 }>>(true)
})

it('works as filter', () => {
Expand Down
15 changes: 7 additions & 8 deletions type-plus/ts/bigint/is_not_strict_bigint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,16 @@ export type IsNotStrictBigint<
: IsNotStrictBigint._N<T, $O>)
: never : never

export namespace IsNotStrictBigint {
export namespace IsNotStrictBigint {
export type $Options = SelectWithDistribute.$Options
export type $Default = SelectWithDistribute.$Default
export type $Branch = SelectWithDistribute.$Branch
export type _D<T, $O extends IsNotStrictBigint.$Options> = (bigint extends T
? (T extends bigint
? (`${T}` extends `${number}`
? $ResolveSelection<$O, T, $Then>
: $ResolveSelection<$O, T, $Else>)
: $ResolveSelection<$O, T, $Then>)
: $ResolveSelection<$O, T, $Then>)
export type _D<T, $O extends IsNotStrictBigint.$Options> =
T extends bigint
? (`${T}` extends `${number}`
? $ResolveSelection<$O, T, $Then>
: $ResolveSelection<$O, T, $Else>)
: $ResolveSelection<$O, T, $Then>
export type _N<T, $O extends IsNotStrictBigint.$Options> = ([bigint, T] extends [T, bigint]
? (T extends bigint
? (`${T}` extends `${number}`
Expand Down
4 changes: 2 additions & 2 deletions type-plus/ts/bigint/is_strict_bigint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ it('can disable union distribution', () => {
testType.equal<IsStrictBigint<bigint | 1, { distributive: false }>, false>(true)
})

it('consider intersection type as not strict', () => {
testType.false<IsStrictBigint<bigint & { a: 1 }>>(true)
it('consider intersection type as strict', () => {
testType.true<IsStrictBigint<bigint & { a: 1 }>>(true)
testType.false<IsStrictBigint<1n & { a: 1 }>>(true)
})

Expand Down
18 changes: 10 additions & 8 deletions type-plus/ts/bigint/is_strict_bigint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,16 @@ export namespace IsStrictBigint {
export type $Options = SelectWithDistribute.$Options
export type $Default = SelectWithDistribute.$Default
export type $Branch = SelectWithDistribute.$Branch
export type _D<T, $O extends IsStrictBigint.$Options> = (bigint extends T
? (T extends bigint
? (`${T}` extends `${number}`
? $ResolveSelection<$O, T, $Else>
: $ResolveSelection<$O, T, $Then>)
: $ResolveSelection<$O, T, $Else>)
: $ResolveSelection<$O, T, $Else>)
export type _N<T, $O extends IsStrictBigint.$Options> = ([bigint, T] extends [T, bigint]
export type _D<T, $O extends IsStrictBigint.$Options> =
T extends bigint
? (
`${T}` extends `${number}`
? $ResolveSelection<$O, T, $Else>
: $ResolveSelection<$O, T, $Then>
)
: $ResolveSelection<$O, T, $Else>
export type _N<T, $O extends IsStrictBigint.$Options> = (
[bigint, T] extends [T, bigint]
? (T extends bigint
? (`${T}` extends `${number}`
? $ResolveSelection<$O, T, $Else>
Expand Down
1 change: 1 addition & 0 deletions type-plus/ts/boolean/is_not_strict_boolean.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ it('can disable union distribution', () => {
})

it('returns false for intersection type', () => {
// `boolean & { a: 1 }` is considered as strict boolean
testType.equal<IsNotStrictBoolean<boolean & { a: 1 }>, false>(true)
})

Expand Down
4 changes: 2 additions & 2 deletions type-plus/ts/boolean/is_not_strict_boolean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type { IsStrictBoolean } from './is_strict_boolean.js'
* type R = IsNotStrictBoolean<number> // true
* type R = IsNotStrictBoolean<unknown> // true
* type R = IsNotStrictBoolean<string | boolean> // boolean
* ```
* ```
*
* 🔢 *customize*
*
Expand Down Expand Up @@ -71,7 +71,7 @@ export type IsNotStrictBoolean<T, $O extends IsNotStrictBoolean.$Options = {}> =
: ['aBcd' | 'Abcd'] extends [R] ? $ResolveSelection<$O, T, $Else> : $ResolveSelection<$O, T, $Then>
: never
)
: [T, boolean] extends [boolean, T] ? $ResolveSelection<$O, T, $Else> : $ResolveSelection<$O, T, $Then>
: SelectInvertStrictWithDistribute._N<T, boolean, $O>
)
: never : never

Expand Down
12 changes: 6 additions & 6 deletions type-plus/ts/boolean/is_strict_boolean.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IsAnyOrNever } from '../mix_types/is_any_or_never.js'
import type { SelectInvertStrictWithDistribute } from '../type_plus/branch/select_invert_strict_with_distribute.js'
import type { SelectStrictWithDistribute } from '../type_plus/branch/select_strict_with_distribute.js'
import type { $Else, $ResolveSelection, $SelectionBranch, $Then } from '../type_plus/branch/selection.js'
import type { $ResolveOptions } from '../type_plus/resolve_options.js'

Expand Down Expand Up @@ -63,22 +63,22 @@ export type IsStrictBoolean<T, $O extends IsStrictBoolean.$Options = {}> = IsAny
> extends infer R
? R extends $Then ? $ResolveSelection<$O, T, $Else>
: R extends $Else ? (
$ResolveOptions<[$O['distributive'], SelectInvertStrictWithDistribute.$Default['distributive']]> extends true
$ResolveOptions<[$O['distributive'], SelectStrictWithDistribute.$Default['distributive']]> extends true
? (
IsStrictBoolean._DistributeMap<T> extends infer R
? ['aBcD' | 'AbCd' | 'abcd'] extends [R] ? $ResolveSelection<$O, boolean, $Then> | $ResolveSelection<$O, Exclude<T, boolean>, $Else>
: ['aBcD' | 'AbCd'] extends [R] ? $ResolveSelection<$O, T, $Then>
: ['aBcd' | 'Abcd'] extends [R] ? $ResolveSelection<$O, T, $Then> : $ResolveSelection<$O, T, $Else>
: never
)
: [T, boolean] extends [boolean, T] ? $ResolveSelection<$O, T, $Then> : $ResolveSelection<$O, T, $Else>
: SelectStrictWithDistribute._N<T, boolean, $O>
)
: never : never

export namespace IsStrictBoolean {
export type $Options = SelectInvertStrictWithDistribute.$Options
export type $Default = SelectInvertStrictWithDistribute.$Default
export type $Branch = SelectInvertStrictWithDistribute.$Branch
export type $Options = SelectStrictWithDistribute.$Options
export type $Default = SelectStrictWithDistribute.$Default
export type $Branch = SelectStrictWithDistribute.$Branch

export type _DistributeMap<T> = T extends true
? (T extends false
Expand Down
59 changes: 0 additions & 59 deletions type-plus/ts/function/function_type.is_not_function.spec.ts

This file was deleted.

57 changes: 0 additions & 57 deletions type-plus/ts/function/function_type.not_function_type.spec.ts

This file was deleted.

59 changes: 0 additions & 59 deletions type-plus/ts/function/function_type.spec.ts

This file was deleted.

67 changes: 0 additions & 67 deletions type-plus/ts/function/function_type.ts

This file was deleted.

Loading

0 comments on commit 33c0208

Please sign in to comment.