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 11import type { Denops } from "@denops/std" ;
22
33import type { Promish } from "./_typeutil.ts" ;
4- import type { IdItem } from "./item.ts" ;
4+ import type { Detail , IdItem } from "./item.ts" ;
55
66/**
77 * Parameters for invoking an action.
88 */
9- export type InvokeParams < T > = {
9+ export type InvokeParams < T extends Detail > = {
1010 /**
1111 * The item currently under the cursor.
1212 *
@@ -28,7 +28,7 @@ export type InvokeParams<T> = {
2828/**
2929 * An action that can be invoked from the picker.
3030 */
31- export type Action < T > = {
31+ export type Action < T extends Detail > = {
3232 /**
3333 * Invoke the action.
3434 *
Original file line number Diff line number Diff line change 11import type { Denops } from "@denops/std" ;
22
3- import type { IdItem } from "./item.ts" ;
3+ import type { Detail , IdItem } from "./item.ts" ;
44
55/**
66 * Parameters for curating items.
@@ -21,7 +21,7 @@ export type CurateParams = {
2121 *
2222 * Acts as an interactive `Source`.
2323 */
24- export type Curator < T > = {
24+ export type Curator < T extends Detail > = {
2525 /**
2626 * Curates items based on the provided parameters.
2727 *
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+
111/**
212 * An item processed by the picker.
313 */
4- export type IdItem < T > = {
14+ export type IdItem < T extends Detail > = {
515 /**
616 * Unique identifier for the item.
717 */
@@ -41,7 +51,7 @@ export type IdItem<T> = {
4151/**
4252 * An item displayed in the picker.
4353 */
44- export type DisplayItem < T > = IdItem < T > & {
54+ export type DisplayItem < T extends Detail > = IdItem < T > & {
4555 /**
4656 * Display label for the item in the picker.
4757 *
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 11import type { Denops } from "@denops/std" ;
2- import type { IdItem } from "./item.ts" ;
2+
3+ import type { Detail , IdItem } from "./item.ts" ;
34
45/**
56 * Parameters for matching items.
67 */
7- export type MatchParams < T > = {
8+ export type MatchParams < T extends Detail > = {
89 /**
910 * User input query for filtering.
1011 */
@@ -18,8 +19,8 @@ export type MatchParams<T> = {
1819/**
1920 * Matcher that filters items based on user input.
2021 */
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.
2324
2425 /**
2526 * Matches items against the provided query.
@@ -29,9 +30,7 @@ export type Matcher<T> = {
2930 * @param options - Additional options, including an abort signal.
3031 * @returns An async iterator over matched `IdItem` elements.
3132 */
32- match <
33- V extends T ,
34- > (
33+ match < V extends T > (
3534 denops : Denops ,
3635 params : MatchParams < V > ,
3736 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- */
121export * from "./action.ts" ;
132export * from "./coordinator.ts" ;
143export * from "./curator.ts" ;
Original file line number Diff line number Diff line change 11import type { Denops } from "@denops/std" ;
22import type { Promish } from "./_typeutil.ts" ;
3- import type { IdItem , PreviewItem } from "./item.ts" ;
3+ import type { Detail , IdItem , PreviewItem } from "./item.ts" ;
44
55/**
66 * Parameters for previewing an item.
77 */
8- export type PreviewParams < T > = {
8+ export type PreviewParams < T extends Detail > = {
99 /**
1010 * The item to preview.
1111 */
@@ -15,7 +15,7 @@ export type PreviewParams<T> = {
1515/**
1616 * Previewer that generates a preview for an item.
1717 */
18- export type Previewer < T > = {
18+ export type Previewer < T extends Detail > = {
1919 /**
2020 * Generates a preview for the specified item.
2121 *
Original file line number Diff line number Diff line change 11import type { Denops } from "@denops/std" ;
22import type { Promish } from "./_typeutil.ts" ;
3- import type { DisplayItem } from "./item.ts" ;
3+ import type { Detail , DisplayItem } from "./item.ts" ;
44
55/**
66 * Parameters for rendering items.
77 */
8- export type RenderParams < T > = {
8+ export type RenderParams < T extends Detail > = {
99 /**
1010 * Array of items to render.
1111 */
@@ -15,7 +15,7 @@ export type RenderParams<T> = {
1515/**
1616 * Renderer responsible for rendering items.
1717 */
18- export type Renderer < T > = {
18+ export type Renderer < T extends Detail > = {
1919 /**
2020 * Renders items in place.
2121 *
Original file line number Diff line number Diff line change 11import type { Denops } from "@denops/std" ;
22import type { Promish } from "./_typeutil.ts" ;
3- import type { IdItem } from "./item.ts" ;
3+ import type { Detail , IdItem } from "./item.ts" ;
44
55/**
66 * Parameters for sorting items.
77 */
8- export type SortParams < T > = {
8+ export type SortParams < T extends Detail > = {
99 /**
1010 * Array of items to sort.
1111 */
@@ -15,7 +15,7 @@ export type SortParams<T> = {
1515/**
1616 * Sorter that arranges items in order.
1717 */
18- export type Sorter < T > = {
18+ export type Sorter < T extends Detail > = {
1919 /**
2020 * Sorts items in place.
2121 *
Original file line number Diff line number Diff line change 11import type { Denops } from "@denops/std" ;
2- import type { IdItem } from "./item.ts" ;
2+ import type { Detail , IdItem } from "./item.ts" ;
33
44/**
55 * Parameters for collecting items.
@@ -14,7 +14,7 @@ export type CollectParams = {
1414/**
1515 * Source that collects items.
1616 */
17- export type Source < T > = {
17+ export type Source < T extends Detail > = {
1818 /**
1919 * Collects items.
2020 *
You can’t perform that action at this time.
0 commit comments