Skip to content

Commit

Permalink
chore: upgrade typescript and use --isolatedDeclarations (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson authored Jun 27, 2024
1 parent a889c60 commit 743238d
Show file tree
Hide file tree
Showing 25 changed files with 124 additions and 105 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish-beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,6 @@ jobs:

- name: Publish to JSR
run: |
deno run -A jsr:@david/[email protected] --allow-slow-types --allow-dirty
deno run -A jsr:@david/[email protected] --allow-dirty
env:
GITHUB_REF: refs/tags/v${{ needs.prepare-version.outputs.version }}
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"source.organizeImports",
"source.formatDocument"
],
"typescript.tsdk": "./node_modules/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true,
"typescript.preferences.importModuleSpecifier": "non-relative",
"typescript.preferences.autoImportFileExcludePatterns": [
"**/node_modules/**",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@vitest/coverage-v8": "^1.6.0",
"prettier": "^2.7.1",
"tsup": "^8.1.0",
"typescript": "^4.8.4",
"typescript": "^5.5.2",
"vitest": "^1.6.0"
},
"packageManager": "[email protected]",
Expand Down
18 changes: 9 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/array/alphabetical.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function alphabetical<T>(
array: readonly T[],
getter: (item: T) => string,
dir: 'asc' | 'desc' = 'asc',
) {
): T[] {
if (!array) {
return []
}
Expand Down
5 changes: 4 additions & 1 deletion src/array/boil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
* boil([1, 2, 3, 0], (a, b) => a > b ? a : b) // 3
* ```
*/
export function boil<T>(array: readonly T[], compareFunc: (a: T, b: T) => T) {
export function boil<T>(
array: readonly T[],
compareFunc: (a: T, b: T) => T,
): T | null {
if (!array || (array.length ?? 0) === 0) {
return null
}
Expand Down
9 changes: 5 additions & 4 deletions src/array/first.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
* // 0
* ```
*/
export function first<T>(
array: readonly T[],
defaultValue: T | null | undefined = undefined,
) {
export function first<T>(array: readonly T[]): T | undefined

export function first<T, U>(array: readonly T[], defaultValue: U): T | U

export function first(array: readonly unknown[], defaultValue?: unknown) {
return array?.length > 0 ? array[0] : defaultValue
}
2 changes: 1 addition & 1 deletion src/array/iterate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function iterate<T>(
count: number,
func: (currentValue: T, iteration: number) => T,
initValue: T,
) {
): T {
let value = initValue
for (let i = 1; i <= count; i++) {
value = func(value, i)
Expand Down
9 changes: 5 additions & 4 deletions src/array/last.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
* // 0
* ```
*/
export function last<T>(
array: readonly T[],
defaultValue: T | null | undefined = undefined,
) {
export function last<T>(array: readonly T[]): T | undefined

export function last<T, U>(array: readonly T[], defaultValue: U): T | U

export function last(array: readonly unknown[], defaultValue?: unknown) {
return array?.length > 0 ? array[array.length - 1] : defaultValue
}
6 changes: 3 additions & 3 deletions src/array/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ export function merge<T>(
root: readonly T[],
others: readonly T[],
matcher: (item: T) => any,
) {
): T[] {
if (!others && !root) {
return []
}
if (!others) {
return root
return [...root]
}
if (!root) {
return []
}
if (!matcher) {
return root
return [...root]
}
return root.reduce((acc, r) => {
const matched = others.find(o => matcher(r) === matcher(o))
Expand Down
5 changes: 5 additions & 0 deletions src/array/replace.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
/**
* Replace an element in an array with a new item without modifying
* the array and return the new value
*
* ```ts
* replace([1, 2, 3], 4, (n) => n === 2)
* // [1, 4, 3]
* ```
*/
export function replace<T>(
list: readonly T[],
Expand Down
2 changes: 1 addition & 1 deletion src/array/replaceOrAppend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function replaceOrAppend<T>(
list: readonly T[],
newItem: T,
match: (a: T, idx: number) => boolean,
) {
): T[] {
if (!list && !newItem) {
return []
}
Expand Down
10 changes: 5 additions & 5 deletions src/array/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@
* // => [9, 16]
* ```
*/
export function select<T, K>(
export function select<T, U>(
array: readonly T[],
mapper: (item: T, index: number) => K,
mapper: (item: T, index: number) => U,
condition?: (item: T, index: number) => boolean,
) {
): U[] {
if (!array) {
return []
}
let mapped: K
let mapped: U
return array.reduce((acc, item, index) => {
if (condition) {
condition(item, index) && acc.push(mapper(item, index))
} else if ((mapped = mapper(item, index)) != null) {
acc.push(mapped)
}
return acc
}, [] as K[])
}, [] as U[])
}
2 changes: 1 addition & 1 deletion src/array/sort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function sort<T>(
array: readonly T[],
getter: (item: T) => number,
desc = false,
) {
): T[] {
if (!array) {
return []
}
Expand Down
2 changes: 1 addition & 1 deletion src/array/toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function toggle<T>(
options?: {
strategy?: 'prepend' | 'append'
},
) {
): T[] {
if (!list && !item) {
return []
}
Expand Down
4 changes: 2 additions & 2 deletions src/async/tests/retry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('_.retry', () => {
vi.useFakeTimers({ shouldAdvanceTime: true })
})
test('returns result of given function', async () => {
const result = await _.retry(cast(null), async bail => {
const result = await _.retry(cast(null), async _bail => {
return 'hello'
})
expect(result).toBe('hello')
Expand All @@ -21,7 +21,7 @@ describe('_.retry', () => {
})
test('retries on failure', async () => {
let failedOnce = false
const result = await _.retry(cast(null), async bail => {
const result = await _.retry(cast(null), async _bail => {
if (!failedOnce) {
failedOnce = true
throw 'Failing for test'
Expand Down
2 changes: 1 addition & 1 deletion src/curry/callable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ export function callable<
;(target as any)[key] = value
return true
},
apply: (target, self, args) => fn(Object.assign({}, target))(...args),
apply: (target, _, args) => fn(Object.assign({}, target))(...args),
}) as unknown as TObj & TFunc
}
2 changes: 1 addition & 1 deletion src/curry/debounce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type DebounceFunction<TArgs extends any[]> = {
export function debounce<TArgs extends any[]>(
{ delay }: { delay: number },
func: (...args: TArgs) => any,
) {
): DebounceFunction<TArgs> {
let timer: unknown = undefined
let active = true

Expand Down
5 changes: 2 additions & 3 deletions src/curry/partial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ type RemoveItemsInFront<
export function partial<T extends any[], TA extends Partial<T>, R>(
fn: (...args: T) => R,
...args: TA
) {
return (...rest: RemoveItemsInFront<T, TA>) =>
fn(...([...args, ...rest] as T))
): (...rest: RemoveItemsInFront<T, TA>) => R {
return (...rest) => fn(...([...args, ...rest] as T))
}
2 changes: 1 addition & 1 deletion src/curry/throttle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type ThrottledFunction<TArgs extends any[]> = {
export function throttle<TArgs extends any[]>(
{ interval }: { interval: number },
func: (...args: TArgs) => any,
) {
): ThrottledFunction<TArgs> {
let ready = true
let timer: unknown = undefined

Expand Down
12 changes: 6 additions & 6 deletions src/object/listify.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/**
* Convert an object to a list, mapping each entry into a list item
*/
export function listify<TValue, TKey extends string | number | symbol, KResult>(
obj: Record<TKey, TValue>,
toItem: (key: TKey, value: TValue) => KResult,
) {
export function listify<Value, Key extends string | number | symbol, Item>(
obj: Record<Key, Value>,
toItem: (key: Key, value: Value) => Item,
): Item[] {
if (!obj) {
return []
}
Expand All @@ -13,7 +13,7 @@ export function listify<TValue, TKey extends string | number | symbol, KResult>(
return []
}
return entries.reduce((acc, entry) => {
acc.push(toItem(entry[0] as TKey, entry[1] as TValue))
acc.push(toItem(entry[0] as Key, entry[1] as Value))
return acc
}, [] as KResult[])
}, [] as Item[])
}
Loading

0 comments on commit 743238d

Please sign in to comment.