Tighter types now fromJS is explicit
This commit is contained in:
parent
4353d5280e
commit
a19a9d50c6
|
@ -77,7 +77,7 @@ export class Record<T extends object = DefaultPointer> extends Array<Value<T>> {
|
||||||
|
|
||||||
static makeBasicConstructor<T extends object = DefaultPointer>(label: Value<T>, fieldNames: string[]): RecordConstructor<T> {
|
static makeBasicConstructor<T extends object = DefaultPointer>(label: Value<T>, fieldNames: string[]): RecordConstructor<T> {
|
||||||
const arity = fieldNames.length;
|
const arity = fieldNames.length;
|
||||||
const ctor: RecordConstructor<T> = (...fields: any[]): Record<T> => {
|
const ctor: RecordConstructor<T> = (...fields: Value<T>[]): Record<T> => {
|
||||||
if (fields.length !== arity) {
|
if (fields.length !== arity) {
|
||||||
throw new Error("Record: cannot instantiate " + (label && label.toString()) +
|
throw new Error("Record: cannot instantiate " + (label && label.toString()) +
|
||||||
" expecting " + arity + " fields with " + fields.length + " fields");
|
" expecting " + arity + " fields with " + fields.length + " fields");
|
||||||
|
@ -89,7 +89,7 @@ export class Record<T extends object = DefaultPointer> extends Array<Value<T>> {
|
||||||
ctor.isClassOf = (v: any): v is Record<T> => Record.isClassOf(constructorInfo, v);
|
ctor.isClassOf = (v: any): v is Record<T> => Record.isClassOf(constructorInfo, v);
|
||||||
ctor._ = {};
|
ctor._ = {};
|
||||||
fieldNames.forEach((name, i) => {
|
fieldNames.forEach((name, i) => {
|
||||||
ctor._[name] = function (r: any): Value<T> | undefined {
|
ctor._[name] = function (r: Value<T>): Value<T> | undefined {
|
||||||
if (!ctor.isClassOf(r)) {
|
if (!ctor.isClassOf(r)) {
|
||||||
throw new Error("Record: attempt to retrieve field "+label.toString()+"."+name+
|
throw new Error("Record: attempt to retrieve field "+label.toString()+"."+name+
|
||||||
" from non-"+label.toString()+": "+(r && r.toString()));
|
" from non-"+label.toString()+": "+(r && r.toString()));
|
||||||
|
@ -121,10 +121,10 @@ export class Record<T extends object = DefaultPointer> extends Array<Value<T>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RecordConstructor<T extends object = DefaultPointer> {
|
export interface RecordConstructor<T extends object = DefaultPointer> {
|
||||||
(...fields: any[]): Record<T>;
|
(...fields: Value<T>[]): Record<T>;
|
||||||
constructorInfo: RecordConstructorInfo<T>;
|
constructorInfo: RecordConstructorInfo<T>;
|
||||||
isClassOf(v: any): v is Record<T>;
|
isClassOf(v: any): v is Record<T>;
|
||||||
_: { [getter: string]: (r: any) => Value<T> | undefined };
|
_: { [getter: string]: (r: Value<T>) => Value<T> | undefined };
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RecordConstructorInfo<T extends object = DefaultPointer> {
|
export interface RecordConstructorInfo<T extends object = DefaultPointer> {
|
||||||
|
|
Loading…
Reference in New Issue