File tree Expand file tree Collapse file tree 10 files changed +95
-36
lines changed Expand file tree Collapse file tree 10 files changed +95
-36
lines changed Original file line number Diff line number Diff line change 1
1
import type { Denops } from "@denops/std" ;
2
2
3
3
import type { Promish } from "./_typeutil.ts" ;
4
- import type { IdItem } from "./item.ts" ;
4
+ import type { Detail , IdItem } from "./item.ts" ;
5
5
6
6
/**
7
7
* Parameters for invoking an action.
8
8
*/
9
- export type InvokeParams < T > = {
9
+ export type InvokeParams < T extends Detail > = {
10
10
/**
11
11
* The item currently under the cursor.
12
12
*
@@ -28,7 +28,7 @@ export type InvokeParams<T> = {
28
28
/**
29
29
* An action that can be invoked from the picker.
30
30
*/
31
- export type Action < T > = {
31
+ export type Action < T extends Detail > = {
32
32
/**
33
33
* Invoke the action.
34
34
*
Original file line number Diff line number Diff line change 1
1
import type { Denops } from "@denops/std" ;
2
2
3
- import type { IdItem } from "./item.ts" ;
3
+ import type { Detail , IdItem } from "./item.ts" ;
4
4
5
5
/**
6
6
* Parameters for curating items.
@@ -21,7 +21,7 @@ export type CurateParams = {
21
21
*
22
22
* Acts as an interactive `Source`.
23
23
*/
24
- export type Curator < T > = {
24
+ export type Curator < T extends Detail > = {
25
25
/**
26
26
* Curates items based on the provided parameters.
27
27
*
Original file line number Diff line number Diff line change
1
+ /**
2
+ * A detail attribute base type.
3
+ */
4
+ export type Detail = Record < PropertyKey , unknown > ;
5
+
6
+ /**
7
+ * An empty detail attribute.
8
+ */
9
+ export type EmptyDetail = Record < never , never > ;
10
+
1
11
/**
2
12
* An item processed by the picker.
3
13
*/
4
- export type IdItem < T > = {
14
+ export type IdItem < T extends Detail > = {
5
15
/**
6
16
* Unique identifier for the item.
7
17
*/
@@ -41,7 +51,7 @@ export type IdItem<T> = {
41
51
/**
42
52
* An item displayed in the picker.
43
53
*/
44
- export type DisplayItem < T > = IdItem < T > & {
54
+ export type DisplayItem < T extends Detail > = IdItem < T > & {
45
55
/**
46
56
* Display label for the item in the picker.
47
57
*
Original file line number Diff line number Diff line change
1
+ import { assertType , type IsExact } from "@std/testing/types" ;
2
+ import type { Detail , EmptyDetail , IdItem } from "./item.ts" ;
3
+
4
+ Deno . test ( "IdItem" , async ( t ) => {
5
+ await t . step ( "id is 'unknown'" , ( ) => {
6
+ const item : IdItem < EmptyDetail > = {
7
+ id : "unknown" ,
8
+ value : "" ,
9
+ detail : { } ,
10
+ } ;
11
+ assertType < IsExact < typeof item , IdItem < EmptyDetail > > > ( true ) ;
12
+ } ) ;
13
+
14
+ await t . step ( "detail must be 'Detail'" , ( ) => {
15
+ const base = { id : "unknown" , value : "" } ;
16
+ const _items : IdItem < Detail > [ ] = [
17
+ {
18
+ ...base ,
19
+ // @ts -expect-error: number is not Detail
20
+ detail : 1 ,
21
+ } ,
22
+ {
23
+ ...base ,
24
+ // @ts -expect-error: string is not Detail
25
+ detail : "" ,
26
+ } ,
27
+ {
28
+ ...base ,
29
+ // @ts -expect-error: boolean is not Detail
30
+ detail : true ,
31
+ } ,
32
+ {
33
+ ...base ,
34
+ // @ts -expect-error: array is not Detail
35
+ detail : [ ] ,
36
+ } ,
37
+ {
38
+ ...base ,
39
+ // @ts -expect-error: Date is not Detail
40
+ detail : new Date ( ) ,
41
+ } ,
42
+ {
43
+ ...base ,
44
+ detail : { } ,
45
+ } ,
46
+ {
47
+ ...base ,
48
+ detail : {
49
+ a : "string" ,
50
+ b : 1 ,
51
+ c : true ,
52
+ d : [ ] ,
53
+ e : new Date ( ) ,
54
+ f : ( ) => { } ,
55
+ 0 : "number" ,
56
+ [ Symbol ( "g" ) ] : "symbol" ,
57
+ } ,
58
+ } ,
59
+ ] ;
60
+ } ) ;
61
+ } ) ;
Original file line number Diff line number Diff line change 1
1
import type { Denops } from "@denops/std" ;
2
- import type { IdItem } from "./item.ts" ;
2
+
3
+ import type { Detail , IdItem } from "./item.ts" ;
3
4
4
5
/**
5
6
* Parameters for matching items.
6
7
*/
7
- export type MatchParams < T > = {
8
+ export type MatchParams < T extends Detail > = {
8
9
/**
9
10
* User input query for filtering.
10
11
*/
@@ -18,8 +19,8 @@ export type MatchParams<T> = {
18
19
/**
19
20
* Matcher that filters items based on user input.
20
21
*/
21
- export type Matcher < T > = {
22
- __phantom ?: T ; // This is required for type constraint.
22
+ export type Matcher < T extends Detail > = {
23
+ __phantom ?: ( _ : T ) => void ; // This is required for type constraint.
23
24
24
25
/**
25
26
* Matches items against the provided query.
@@ -29,9 +30,7 @@ export type Matcher<T> = {
29
30
* @param options - Additional options, including an abort signal.
30
31
* @returns An async iterator over matched `IdItem` elements.
31
32
*/
32
- match <
33
- V extends T ,
34
- > (
33
+ match < V extends T > (
35
34
denops : Denops ,
36
35
params : MatchParams < V > ,
37
36
options : { signal ?: AbortSignal } ,
Original file line number Diff line number Diff line change 1
- /**
2
- * Core types for [Fall](https://github.com/vim-fall/fall), a Vim/Neovim fuzzy
3
- * finder plugin powered by [Denops](https://github.com/vim-denops/denops.vim).
4
- *
5
- * > [!WARNING]
6
- * >
7
- * > This module is intended for internal use only and is not meant for external
8
- * > use.
9
- *
10
- * @module
11
- */
12
1
export * from "./action.ts" ;
13
2
export * from "./coordinator.ts" ;
14
3
export * from "./curator.ts" ;
Original file line number Diff line number Diff line change 1
1
import type { Denops } from "@denops/std" ;
2
2
import type { Promish } from "./_typeutil.ts" ;
3
- import type { IdItem , PreviewItem } from "./item.ts" ;
3
+ import type { Detail , IdItem , PreviewItem } from "./item.ts" ;
4
4
5
5
/**
6
6
* Parameters for previewing an item.
7
7
*/
8
- export type PreviewParams < T > = {
8
+ export type PreviewParams < T extends Detail > = {
9
9
/**
10
10
* The item to preview.
11
11
*/
@@ -15,7 +15,7 @@ export type PreviewParams<T> = {
15
15
/**
16
16
* Previewer that generates a preview for an item.
17
17
*/
18
- export type Previewer < T > = {
18
+ export type Previewer < T extends Detail > = {
19
19
/**
20
20
* Generates a preview for the specified item.
21
21
*
Original file line number Diff line number Diff line change 1
1
import type { Denops } from "@denops/std" ;
2
2
import type { Promish } from "./_typeutil.ts" ;
3
- import type { DisplayItem } from "./item.ts" ;
3
+ import type { Detail , DisplayItem } from "./item.ts" ;
4
4
5
5
/**
6
6
* Parameters for rendering items.
7
7
*/
8
- export type RenderParams < T > = {
8
+ export type RenderParams < T extends Detail > = {
9
9
/**
10
10
* Array of items to render.
11
11
*/
@@ -15,7 +15,7 @@ export type RenderParams<T> = {
15
15
/**
16
16
* Renderer responsible for rendering items.
17
17
*/
18
- export type Renderer < T > = {
18
+ export type Renderer < T extends Detail > = {
19
19
/**
20
20
* Renders items in place.
21
21
*
Original file line number Diff line number Diff line change 1
1
import type { Denops } from "@denops/std" ;
2
2
import type { Promish } from "./_typeutil.ts" ;
3
- import type { IdItem } from "./item.ts" ;
3
+ import type { Detail , IdItem } from "./item.ts" ;
4
4
5
5
/**
6
6
* Parameters for sorting items.
7
7
*/
8
- export type SortParams < T > = {
8
+ export type SortParams < T extends Detail > = {
9
9
/**
10
10
* Array of items to sort.
11
11
*/
@@ -15,7 +15,7 @@ export type SortParams<T> = {
15
15
/**
16
16
* Sorter that arranges items in order.
17
17
*/
18
- export type Sorter < T > = {
18
+ export type Sorter < T extends Detail > = {
19
19
/**
20
20
* Sorts items in place.
21
21
*
Original file line number Diff line number Diff line change 1
1
import type { Denops } from "@denops/std" ;
2
- import type { IdItem } from "./item.ts" ;
2
+ import type { Detail , IdItem } from "./item.ts" ;
3
3
4
4
/**
5
5
* Parameters for collecting items.
@@ -14,7 +14,7 @@ export type CollectParams = {
14
14
/**
15
15
* Source that collects items.
16
16
*/
17
- export type Source < T > = {
17
+ export type Source < T extends Detail > = {
18
18
/**
19
19
* Collects items.
20
20
*
You can’t perform that action at this time.
0 commit comments