New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@anywidget/types

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@anywidget/types - npm Package Compare versions

Comparing version

to
0.1.3

test-d.ts

6

CHANGELOG.md
# @anywidget/types
## 0.1.3
### Patch Changes
- feat: Infer event payloads from model ([`272782b`](https://github.com/manzt/anywidget/commit/272782bb919355854cf23ccba430c87b7cc28523))
## 0.1.2

@@ -4,0 +10,0 @@

47

index.d.ts

@@ -1,15 +0,6 @@

type MaybePromise<T> = T | Promise<T>;
type Awaitable<T> = T | Promise<T>;
type ObjectHash = Record<string, any>;
type CleanupFn = () => MaybePromise<void>;
type ChangeEventHandler<Payload> = (_: unknown, value: Payload) => void;
type EventHandler = (...args: any[]) => void;
/**
* JavaScript events (used in the methods of the Events interface)
*/
interface EventHandler {
(...args: any[]): void;
}
/**
* Utility type to infer possible event names from a model.
*
* Autocomplete works for literal string unions, but adding a union

@@ -21,3 +12,3 @@ * of `string` negates autocomplete entirely. This is a workaround

*/
type EventName<T extends PropertyKey> = `change:${T & string}` | 'msg:custom' | (string & {});
type LiteralUnion<T, U = string> = T | (U & {});

@@ -27,6 +18,26 @@ export interface AnyModel<T extends ObjectHash = ObjectHash> {

set<K extends keyof T>(key: K, value: T[K]): void;
off<K extends keyof T>(eventName?: EventName<K> | null, callback?: EventHandler | null): void;
on<K extends keyof T>(eventName: EventName<K>, callback: EventHandler): void;
off<K extends keyof T>(
eventName?: LiteralUnion<`change:${K & string}` | "msg:custom"> | null,
callback?: EventHandler | null,
): void;
on(
eventName: "msg:custom",
callback: (msg: any, buffers: DataView[]) => void,
): void;
on<K extends `change:${keyof T & string}`>(
eventName: K,
callback: K extends `change:${infer Key}` ? ChangeEventHandler<T[Key]>
: never,
): void;
on<K extends `change:${string}`>(
eventName: K,
callback: ChangeEventHandler<any>,
): void;
on(eventName: string, callback: EventHandler): void;
save_changes(): void;
send(content: any, callbacks?: any, buffers?: ArrayBuffer[] | ArrayBufferView[]): void;
send(
content: any,
callbacks?: any,
buffers?: ArrayBuffer[] | ArrayBufferView[],
): void;
}

@@ -40,3 +51,5 @@

export interface Render<T extends ObjectHash = ObjectHash> {
(context: RenderContext<T>): MaybePromise<void | CleanupFn>;
(context: RenderContext<T>): Awaitable<void | (() => Awaitable<void>)>;
}
{
"name": "@anywidget/types",
"type": "module",
"version": "0.1.2",
"version": "0.1.3",
"description": "utility types for anywidget",

@@ -16,4 +16,4 @@ "main": "index.js",

"scripts": {
"typecheck": "tsc --noEmit"
"typecheck": "vitest typecheck --run"
}
}

@@ -35,2 +35,1 @@ # @anywidget/types

MIT
{
"extends": "../../tsconfig.json"
"extends": "../../tsconfig.json",
"compilerOptions": {
"moduleResolution": "node",
"esModuleInterop": true,
// TODO: We want to typecheck index.d.ts but not the
// rest of the node_modules.
// "skipLibCheck": false
}
}