(opts: {
required?: R,
optional?: O,
})
| 63 | } |
| 64 | |
| 65 | strings< |
| 66 | R extends {[key: string]: true}, |
| 67 | O extends {[key: string]: true}, |
| 68 | >(opts: { |
| 69 | required?: R, |
| 70 | optional?: O, |
| 71 | }): { [key in keyof R]: string } |
| 72 | & { [key in keyof O]: string | undefined } |
| 73 | { |
| 74 | const required: Array<keyof R> = Object.keys(opts.required ?? {}); |
| 75 | const optional: Array<keyof O> = Object.keys(opts.optional ?? {}); |
| 76 | type T = keyof R | keyof O; |
| 77 | |
| 78 | const obj = Object.create(null); |
| 79 | const missing = new Set(required); |
| 80 | const strings: Set<T> = new Set(new Array<keyof O|keyof R>().concat(required, optional)); |
| 81 | for (const child of this.children) { |
| 82 | if (strings.has(child.name)) { |
| 83 | obj[child.name as T] = child.content ?? ''; |
| 84 | missing.delete(child.name); |
| 85 | } |
| 86 | } |
| 87 | if (missing.size > 0) this.throwMissingKeys(missing); |
| 88 | return obj; |
| 89 | } |
| 90 | |
| 91 | throwMissingKeys(missingKeys: Iterable<string|number|symbol>): never { |
| 92 | throw new Error(`BUG: XmlNode ${JSON.stringify(this.name) |
no test coverage detected