Open
Description
Bug Report
This error is probably self-explanatory. Either this is supposed to work and it’s a bug, or I’m misunderstanding something in which case please feel free to close.
Type '(Record<string, any> | null)[] & { length: 2; }' is not assignable to type '[Record<string, any> | null, Record<string, any> | null]'.ts(2322)
Outer function is typed to return the latter. It calls an inner function, typed to return the former. One would assume this should work.
Possibly related: #44309
🔎 Search Terms
array literal length
🕗 Version & Regression Information
TypeScript 4.1.3
💻 Code
async function readObjectVersions
<L extends number, C extends string[] & { length: L }>
(objectPath: string, versions: C):
Promise<(Record<string, any> | null)[] & { length: L }> {
return versions.map(version => ({ foo: 'bar' }));
}
const version1: string = 'x';
const version2: string = 'y';
async function _readObjectVersions(objectPath: string):
Promise<[ Record<string, any> | null, Record<string, any> | null ]> {
return await readObjectVersions(objectPath, [version1, version2]);
}
_readObjectVersions('abc');
🙁 Actual behavior
The error as described above.
🙂 Expected behavior
No type error.