diff --git a/types/node/diagnostics_channel.d.ts b/types/node/diagnostics_channel.d.ts index a88c7454d716d5..a6deb7dcd6e17d 100644 --- a/types/node/diagnostics_channel.d.ts +++ b/types/node/diagnostics_channel.d.ts @@ -33,7 +33,10 @@ declare module "node:diagnostics_channel" { * @param name The channel name * @return The named channel object */ - function channel(name: string | symbol): Channel; + // eslint-disable-next-line @definitelytyped/no-unnecessary-generics + function channel( + name: string | symbol, + ): Channel; type ChannelListener = (message: unknown, name: string | symbol) => void; /** * Register a message handler to subscribe to this channel. This message handler @@ -96,12 +99,9 @@ declare module "node:diagnostics_channel" { * @param nameOrChannels Channel name or object containing all the `TracingChannel Channels` * @return Collection of channels to trace with */ - function tracingChannel< - StoreType = unknown, - ContextType extends object = StoreType extends object ? StoreType : object, - >( - nameOrChannels: string | TracingChannelCollection, - ): TracingChannel; + function tracingChannel( + nameOrChannels: string | TracingChannelCollection, + ): TracingChannel; /** * The class `Channel` represents an individual named channel within the data * pipeline. It is used to track subscribers and to publish messages when there @@ -111,7 +111,7 @@ declare module "node:diagnostics_channel" { * with `new Channel(name)` is not supported. * @since v15.1.0, v14.17.0 */ - class Channel { + class Channel { readonly name: string | symbol; /** * Check if there are active subscribers to this channel. This is helpful if @@ -304,12 +304,12 @@ declare module "node:diagnostics_channel" { }, ) => void; } - interface TracingChannelCollection { - start: Channel; - end: Channel; - asyncStart: Channel; - asyncEnd: Channel; - error: Channel; + interface TracingChannelCollection { + start: Channel; + end: Channel; + asyncStart: Channel; + asyncEnd: Channel; + error: Channel; } /** * The class `TracingChannel` is a collection of `TracingChannel Channels` which @@ -320,12 +320,9 @@ declare module "node:diagnostics_channel" { * @since v19.9.0 * @experimental */ - class TracingChannel implements TracingChannelCollection { - start: Channel; - end: Channel; - asyncStart: Channel; - asyncEnd: Channel; - error: Channel; + interface TracingChannel + extends TracingChannelCollection + { /** * Helper to subscribe a collection of functions to the corresponding channels. * This is the same as calling `channel.subscribe(onMessage)` on each channel diff --git a/types/node/node-tests/diagnostics_channel.ts b/types/node/node-tests/diagnostics_channel.ts index be47b2a12a9398..7ec4d7600bef12 100644 --- a/types/node/node-tests/diagnostics_channel.ts +++ b/types/node/node-tests/diagnostics_channel.ts @@ -25,22 +25,21 @@ unsubscribe(Symbol.for("test-symbol"), listener); const hasSubs = hasSubscribers("test"); { - const channelsByName = tracingChannel("my-channel"); - channelsByName.start; // $ExpectType Channel + const channelsByName = tracingChannel<{ requestId: number }, number>("my-channel"); + channelsByName.start; // $ExpectType Channel<{ requestId: number }, number> - type MyChannel = Channel; const channelsByCollection = tracingChannel({ - start: channel("tracing:my-channel:start") as MyChannel, - end: channel("tracing:my-channel:end") as MyChannel, - asyncStart: channel("tracing:my-channel:asyncStart") as MyChannel, - asyncEnd: channel("tracing:my-channel:asyncEnd") as MyChannel, - error: channel("tracing:my-channel:error") as MyChannel, + start: channel<{ requestId: number }, number>("tracing:my-channel:start"), + end: channel<{ requestId: number }, number>("tracing:my-channel:end"), + asyncStart: channel<{ requestId: number }, number>("tracing:my-channel:asyncStart"), + asyncEnd: channel<{ requestId: number }, number>("tracing:my-channel:asyncEnd"), + error: channel<{ requestId: number }, number>("tracing:my-channel:error"), }); - channelsByCollection.start; // $ExpectType Channel + channelsByCollection.start; // $ExpectType Channel<{ requestId: number }, number> } { - const channels = tracingChannel("my-channel"); + const channels = tracingChannel<{ requestId: number }, number>("my-channel"); const store = new AsyncLocalStorage(); channels.start.bindStore(store); diff --git a/types/object-treeify/.npmignore b/types/object-treeify/.npmignore new file mode 100644 index 00000000000000..93e307400a5456 --- /dev/null +++ b/types/object-treeify/.npmignore @@ -0,0 +1,5 @@ +* +!**/*.d.ts +!**/*.d.cts +!**/*.d.mts +!**/*.d.*.ts diff --git a/types/object-treeify/index.d.ts b/types/object-treeify/index.d.ts new file mode 100644 index 00000000000000..404de2a01666d3 --- /dev/null +++ b/types/object-treeify/index.d.ts @@ -0,0 +1,23 @@ +export type RenderFunction = (node: unknown) => unknown; + +export type SortFunction = (firstKey: string, secondKey: string) => number; + +export interface Options { + joined?: boolean; + spacerNoNeighbour?: string; + spacerNeighbour?: string; + keyNoNeighbour?: string; + keyNeighbour?: string; + separator?: string; + renderFn?: RenderFunction; + sortFn?: SortFunction | null; + breakCircularWith?: string | null; +} + +declare function treeify(tree: object, options: Options & { joined: false }): string[]; + +declare function treeify(tree: object, options?: Options & { joined?: true }): string; + +declare function treeify(tree: object, options: Options): string | string[]; + +export default treeify; diff --git a/types/object-treeify/object-treeify-tests.ts b/types/object-treeify/object-treeify-tests.ts new file mode 100644 index 00000000000000..64b950660d9f8b --- /dev/null +++ b/types/object-treeify/object-treeify-tests.ts @@ -0,0 +1,30 @@ +import treeify, { type Options, type RenderFunction, type SortFunction } from "object-treeify"; + +const tree = { + parent: { + child: "value", + }, +}; + +// $ExpectType string +treeify(tree); + +// $ExpectType string[] +treeify(tree, { joined: false }); + +const renderFn: RenderFunction = (node) => node; +const sortFn: SortFunction = (firstKey, secondKey) => firstKey.localeCompare(secondKey); +const options: Options = { + renderFn, + sortFn, + breakCircularWith: null, +}; + +// $ExpectType string | string[] +treeify(tree, options); + +// @ts-expect-error for unsupported option +treeify(tree, { unknownOption: true }); + +// @ts-expect-error for invalid return type +treeify(tree, { sortFn: () => "invalid" }); diff --git a/types/object-treeify/package.json b/types/object-treeify/package.json new file mode 100644 index 00000000000000..aa22d5e23f82c7 --- /dev/null +++ b/types/object-treeify/package.json @@ -0,0 +1,18 @@ +{ + "private": true, + "name": "@types/object-treeify", + "version": "5.0.9999", + "type": "module", + "projects": [ + "https://github.com/blackflux/object-treeify" + ], + "devDependencies": { + "@types/object-treeify": "workspace:." + }, + "owners": [ + { + "name": "Patrik Csak", + "githubUsername": "patrik-csak" + } + ] +} diff --git a/types/object-treeify/tsconfig.json b/types/object-treeify/tsconfig.json new file mode 100644 index 00000000000000..0c30b9068d4af0 --- /dev/null +++ b/types/object-treeify/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "node16", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "object-treeify-tests.ts" + ] +}