Skip to content

Commit d73b643

Browse files
committed
more improve
1 parent 2a3dd23 commit d73b643

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/collection.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { test, expect, expectTypeOf } from 'vitest'
2-
import { Collection } from './collection'
2+
import { Collection, type UniqueWithLocations } from './collection'
33

44
let loc = { start: { line: 1, column: 1, offset: 1 }, end: { offset: 2 } }
55

@@ -44,7 +44,7 @@ test('count with useLocations=false', () => {
4444
expectTypeOf(count['uniqueWithLocations']).toBeUndefined()
4545
})
4646

47-
test('count with useLocations=false', () => {
47+
test('count with useLocations=true', () => {
4848
let collection = new Collection(true)
4949
collection.p('a', loc)
5050
collection.p('a', loc)
@@ -58,5 +58,5 @@ test('count with useLocations=false', () => {
5858
uniquenessRatio: 0.5,
5959
uniqueWithLocations: { a: [pos, pos] },
6060
})
61-
expectTypeOf(count['uniqueWithLocations']).not.toBeUndefined()
61+
expectTypeOf(count['uniqueWithLocations']).toMatchObjectType<UniqueWithLocations>()
6262
})

src/collection.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ export type Location = {
55
length: number
66
}
77

8+
export type UniqueWithLocations = Record<string, Location[]>
9+
810
export type CollectionCount<WithLocations extends boolean = false> = {
911
total: number
1012
totalUnique: number
1113
unique: Record<string, number>
1214
uniquenessRatio: number
13-
} & (WithLocations extends true
14-
? { uniqueWithLocations: Record<string, Location[]> }
15-
: { uniqueWithLocations?: undefined })
15+
} & (WithLocations extends true ? { uniqueWithLocations: UniqueWithLocations } : { uniqueWithLocations?: undefined })
1616

1717
export class Collection<UseLocations extends boolean = false> {
1818
#items: Map<string | number, number[]>

0 commit comments

Comments
 (0)