8000 :bug: Improve type inference · TomokiMiyauci/fonction@2744d04 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 2744d04

Browse files
committed
🐛 Improve type inference
Closes #112
1 parent db20f47 commit 2744d04

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

api.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const api: Api = {
2424
lodash: 'entries'
2525
},
2626
F: LAMBDAS,
27-
first: {
27+
head: {
2828
ramda: 'head',
2929
rambda: 'head',
3030
lodash: 'first'
@@ -37,7 +37,7 @@ const api: Api = {
3737
gt: ['ramda', 'lodash'],
3838
gte: ['ramda', 'lodash'],
3939
has: ALL_MODULES,
40-
head: {
40+
init: {
4141
rambda: 'init',
4242
ramda: 'init',
4343
lodash: 'initial'

mod.ts

+2
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ export { gt } from './src/gt.ts'
2222
export { gte } from './src/gte.ts'
2323
export { has } from './src/has.ts'
2424
export { hasPath } from './src/hasPath.ts'
25+
export type { Head } from './src/head.ts'
2526
export { head } from './src/head.ts'
2627
export { identity } from './src/identity.ts'
2728
export { ifElse } from './src/ifElse.ts'
2829
export { ifElseFn } from './src/ifElseFn.ts'
2930
export { inc } from './src/inc.ts'
3031
export { includes } from './src/includes.ts'
32+
export { init } from './src/init.ts'
3133
export { isArray } from './src/isArray.ts'
3234
export { isBigint } from './src/isBigint.ts'
3335
export { isBoolean } from './src/isBoolean.ts'

src/last.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,11 @@ type Last<T extends string | readonly unknown[]> = T extends ''
3737
? String2Array<T> extends []
3838
? string
3939
: [never, ...String2Array<T>][String2Array<T>['length']]
40-
: T extends never[] | readonly never[]
40+
: T extends never[] | []
4141
? undefined
42-
: T extends unknown[] | readonly unknown[]
43-
? [never, ...T][T['length']]
44-
: T extends string
45-
? string
46-
: never
42+
: T extends readonly [...infer _, infer L]
43+
? L
44+
: T[T['length']] | undefined
4745

4846
/**
4947
* Returns the last element of the given list or string.

test/last.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ Deno.test('last', () => {
4848
Deno.test('Last', () => {
4949
assertEqual<undefined, Last<[] | never[] | readonly [] | readonly never[]>>()
5050
assertEqual<'', Last<[''] | readonly ['']>>()
51-
assertEqual<string, Last<string[]>>()
52-
assertEqual<string | number, Last<string | number[]>>()
51+
assertEqual<string | undefined, Last<string[]>>()
52+
assertEqual<string | number | undefined, Last<string | number[]>>()
5353
assertEqual<[], Last<[100, 200, 'hello', []]>>()
5454
assertEqual<string, Last<string>>()
5555
assertEqual<'', Last<''>>()

0 commit comments

Comments
 (0)
0