Add regression test

This commit is contained in:
Anders Hejlsberg 2019-09-25 09:34:24 -07:00
parent 8e232e4d28
commit cefd1e4251

View File

@ -156,3 +156,72 @@ function f42(x: number) {
}
x; // Unreachable
}
// Repro from #33582
export interface Component<T extends object = any> {
attrName?: string;
data: T;
dependencies?: string[];
el: any;
id: string;
multiple?: boolean;
name: string;
schema: unknown;
system: any;
init(data?: T): void;
pause(): void;
play(): void;
remove(): void;
tick?(time: number, timeDelta: number): void;
update(oldData: T): void;
updateSchema?(): void;
extendSchema(update: unknown): void;
flushToDOM(): void;
}
export interface ComponentConstructor<T extends object> {
new (el: unknown, attrValue: string, id: string): T & Component;
prototype: T & {
name: string;
system: unknown;
play(): void;
pause(): void;
};
}
declare function registerComponent<T extends object>(
name: string,
component: ComponentDefinition<T>
): ComponentConstructor<T>;
export type ComponentDefinition<T extends object = object> = T & Partial<Component> & ThisType<T & Component>;
const Component = registerComponent('test-component', {
schema: {
myProperty: {
default: [],
parse() {
return [true];
}
},
string: { type: 'string' },
num: 0
},
init() {
this.data.num = 0;
this.el.setAttribute('custom-attribute', 'custom-value');
},
update() {},
tick() {},
remove() {},
pause() {},
play() {},
multiply(f: number) {
// Reference to system because both were registered with the same name.
return f * this.data.num * this.system!.data.counter;
}
});