This change brings increased type safety to uses of XmlAttributeComponent. Now the compiler is checkign for us that the properties that get passed in to every subclass match the intended interface, and also that the xmlKeys property -> xml attribute mapping has all the right keys
33 lines
789 B
TypeScript
33 lines
789 B
TypeScript
import { Attributes, XmlAttributeComponent, XmlComponent } from "../docx/xml-components";
|
|
|
|
class AbstractNumId extends XmlComponent {
|
|
|
|
constructor(value: number) {
|
|
super("w:abstractNumId");
|
|
this.root.push(new Attributes({
|
|
val: value,
|
|
}));
|
|
}
|
|
}
|
|
|
|
interface INumAttributesProperties {
|
|
numId: number;
|
|
}
|
|
|
|
class NumAttributes extends XmlAttributeComponent<INumAttributesProperties> {
|
|
protected xmlKeys = {numId: "w:numId"};
|
|
}
|
|
|
|
export class Num extends XmlComponent {
|
|
public id: number;
|
|
|
|
constructor(numId: number, abstractNumId: number) {
|
|
super("w:num");
|
|
this.root.push(new NumAttributes({
|
|
numId: numId,
|
|
}));
|
|
this.root.push(new AbstractNumId(abstractNumId));
|
|
this.id = numId;
|
|
}
|
|
}
|