1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
//// [accessorsOverrideProperty8.ts]
type Types = 'boolean' | 'unknown' | 'string';
type Properties<T extends { [key: string]: Types }> = {
readonly [key in keyof T]: T[key] extends 'boolean' ? boolean : T[key] extends 'string' ? string : unknown
}
type AnyCtor<P extends object> = new (...a: any[]) => P
declare function classWithProperties<T extends { [key: string]: Types }, P extends object>(properties: T, klass: AnyCtor<P>): {
new(): P & Properties<T>;
prototype: P & Properties<T>
};
const Base = classWithProperties({
get x() { return 'boolean' as const },
y: 'string',
}, class Base {
});
class MyClass extends Base {
get x() {
return false;
}
get y() {
return 'hi'
}
}
const mine = new MyClass();
const value = mine.x;
//// [accessorsOverrideProperty8.js]
const Base = classWithProperties({
get x() { return 'boolean'; },
y: 'string',
}, class Base {
});
class MyClass extends Base {
get x() {
return false;
}
get y() {
return 'hi';
}
}
const mine = new MyClass();
const value = mine.x;
|