fork of hey-api/openapi-ts because I need some additional things
1import type { SymbolKind } from '../symbols/types';
2
3const kindRank: Record<SymbolKind, number> = {
4 class: 3,
5 enum: 4,
6 function: 5,
7 interface: 1,
8 namespace: 0,
9 type: 2,
10 var: 6,
11};
12
13/**
14 * Returns true if two declarations of given kinds
15 * are allowed to share the same identifier in TypeScript.
16 */
17export function canShareName(a: SymbolKind, b: SymbolKind): boolean {
18 // sort based on TypeScript merge precedence so `a` is always the weaker merge candidate
19 // ensures that asymmetric merges like `type + var` are correctly handled
20 if (kindRank[a] > kindRank[b]) {
21 [a, b] = [b, a];
22 }
23
24 switch (a) {
25 case 'interface':
26 return b === 'class' || b === 'interface';
27 case 'namespace':
28 return b === 'class' || b === 'enum' || b === 'function' || b === 'namespace';
29 case 'type':
30 // type can only merge with value-only declarations
31 return b === 'function' || b === 'var';
32 default:
33 return false;
34 }
35}