fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #2897 from hey-api/copilot/fix-plugininstance-foreach-typing

authored by

Lubos and committed by
GitHub
505b92b4 cec4739a

+30 -23
+5
.changeset/wicked-comics-hang.md
··· 1 + --- 2 + "@hey-api/openapi-ts": patch 3 + --- 4 + 5 + fix(types): use unique generic names in `PluginInstance` to avoid typing issues
+25 -23
packages/openapi-ts/src/plugins/shared/utils/instance.ts
··· 115 115 * This ensures, for example, that schemas are always processed before 116 116 * operations, which may reference them. 117 117 * 118 - * @template T - The event type(s) to yield. Defaults to all event types. 118 + * @template TKind - The event type(s) to yield. Defaults to all event types. 119 119 * @param events - The event types to walk over. If none are provided, all event types are included. 120 120 * @param callback - Function to execute for each event. 121 121 * ··· 129 129 * } 130 130 * }); 131 131 */ 132 - forEach<T extends IrTopLevelKind = IrTopLevelKind>( 132 + forEach<TKind extends IrTopLevelKind = IrTopLevelKind>( 133 133 ...args: [ 134 - ...events: ReadonlyArray<T>, 135 - callback: (event: WalkEvent<T>) => void, 134 + ...events: ReadonlyArray<TKind>, 135 + callback: (event: WalkEvent<TKind>) => void, 136 136 ] 137 137 ): void; 138 - forEach<T extends IrTopLevelKind = IrTopLevelKind>( 138 + forEach<TKind extends IrTopLevelKind = IrTopLevelKind>( 139 139 ...args: [ 140 - ...events: ReadonlyArray<T>, 141 - callback: (event: WalkEvent<T>) => void, 142 - options: WalkOptions<T>, 140 + ...events: ReadonlyArray<TKind>, 141 + callback: (event: WalkEvent<TKind>) => void, 142 + options: WalkOptions<TKind>, 143 143 ] 144 144 ): void; 145 - forEach<T extends IrTopLevelKind = IrTopLevelKind>( 145 + forEach<TKind extends IrTopLevelKind = IrTopLevelKind>( 146 146 ...args: [ 147 - ...events: ReadonlyArray<T>, 148 - callback: (event: WalkEvent<T>) => void, 147 + ...events: ReadonlyArray<TKind>, 148 + callback: (event: WalkEvent<TKind>) => void, 149 149 options: any, 150 150 ] 151 151 ): void { ··· 153 153 throw new Error('No graph available in context'); 154 154 } 155 155 156 - let callback: (event: WalkEvent<T>) => void; 157 - let events: ReadonlyArray<T>; 158 - let options: WalkOptions<T> = { 156 + let callback: (event: WalkEvent<TKind>) => void; 157 + let events: ReadonlyArray<TKind>; 158 + let options: WalkOptions<TKind> = { 159 159 getPointerPriority: getIrPointerPriority, 160 160 // default functions operate on the full union of kinds; cast them 161 161 // to the WalkOptions generic to keep strict typing for callers. 162 162 matchPointerToGroup: 163 - matchIrPointerToGroup as unknown as MatchPointerToGroupFn<T>, 163 + matchIrPointerToGroup as unknown as MatchPointerToGroupFn<TKind>, 164 164 order: 'topological', 165 - preferGroups: preferGroups as unknown as ReadonlyArray<T>, 165 + preferGroups: preferGroups as unknown as ReadonlyArray<TKind>, 166 166 }; 167 167 if (typeof args[args.length - 1] === 'function') { 168 168 events = args.slice(0, -1); ··· 241 241 } 242 242 if (event) { 243 243 try { 244 - callback(event as WalkEvent<T>); 244 + callback(event as WalkEvent<TKind>); 245 245 } catch (error) { 246 246 this.forEachError(error, event); 247 247 } ··· 259 259 * @param name Plugin name as defined in the configuration. 260 260 * @returns The plugin instance if found, undefined otherwise. 261 261 */ 262 - getPlugin<T extends keyof PluginConfigMap>( 263 - name: T, 264 - ): T extends any ? PluginInstance<PluginConfigMap[T]> | undefined : never { 262 + getPlugin<TName extends keyof PluginConfigMap>( 263 + name: TName, 264 + ): TName extends any 265 + ? PluginInstance<PluginConfigMap[TName]> | undefined 266 + : never { 265 267 return this.context.plugins[name] as any; 266 268 } 267 269 ··· 273 275 * @param name Plugin name as defined in the configuration. 274 276 * @returns The plugin instance if found, throw otherwise. 275 277 */ 276 - getPluginOrThrow<T extends keyof PluginConfigMap>( 277 - name: T, 278 - ): T extends any ? PluginInstance<PluginConfigMap[T]> : never { 278 + getPluginOrThrow<TName extends keyof PluginConfigMap>( 279 + name: TName, 280 + ): TName extends any ? PluginInstance<PluginConfigMap[TName]> : never { 279 281 const plugin = this.getPlugin(name); 280 282 if (!plugin) throw new Error(`plugin not found ${name}`); 281 283 return plugin as any;