Skip to content

Commit

Permalink
🐛 Improve type inference
Browse files Browse the repository at this point in the history
Closes #112
  • Loading branch information
TomokiMiyauci committed Jun 28, 2021
1 parent db20f47 commit 2744d04
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const api: Api = {
lodash: 'entries'
},
F: LAMBDAS,
first: {
head: {
ramda: 'head',
rambda: 'head',
lodash: 'first'
Expand All @@ -37,7 +37,7 @@ const api: Api = {
gt: ['ramda', 'lodash'],
gte: ['ramda', 'lodash'],
has: ALL_MODULES,
head: {
init: {
rambda: 'init',
ramda: 'init',
lodash: 'initial'
Expand Down
2 changes: 2 additions & 0 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ export { gt } from './src/gt.ts'
export { gte } from './src/gte.ts'
export { has } from './src/has.ts'
export { hasPath } from './src/hasPath.ts'
export type { Head } from './src/head.ts'
export { head } from './src/head.ts'
export { identity } from './src/identity.ts'
export { ifElse } from './src/ifElse.ts'
export { ifElseFn } from './src/ifElseFn.ts'
export { inc } from './src/inc.ts'
export { includes } from './src/includes.ts'
export { init } from './src/init.ts'
export { isArray } from './src/isArray.ts'
export { isBigint } from './src/isBigint.ts'
export { isBoolean } from './src/isBoolean.ts'
Expand Down
10 changes: 4 additions & 6 deletions src/last.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@ type Last<T extends string | readonly unknown[]> = T extends ''
? String2Array<T> extends []
? string
: [never, ...String2Array<T>][String2Array<T>['length']]
: T extends never[] | readonly never[]
: T extends never[] | []
? undefined
: T extends unknown[] | readonly unknown[]
? [never, ...T][T['length']]
: T extends string
? string
: never
: T extends readonly [...infer _, infer L]
? L
: T[T['length']] | undefined

/**
* Returns the last element of the given list or string.
Expand Down
4 changes: 2 additions & 2 deletions test/last.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ Deno.test('last', () => {
Deno.test('Last', () => {
assertEqual<undefined, Last<[] | never[] | readonly [] | readonly never[]>>()
assertEqual<'', Last<[''] | readonly ['']>>()
assertEqual<string, Last<string[]>>()
assertEqual<string | number, Last<string | number[]>>()
assertEqual<string | undefined, Last<string[]>>()
assertEqual<string | number | undefined, Last<string | number[]>>()
assertEqual<[], Last<[100, 200, 'hello', []]>>()
assertEqual<string, Last<string>>()
assertEqual<'', Last<''>>()
Expand Down

0 comments on commit 2744d04

Please sign in to comment.