-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
TypeScript Version: 3.5.1
Search Terms: infer array destruction
Code
// A *self-contained* demonstration of the problem follows...
// Test this by running `tsc` on the command-line, rather than through another build tool such as Gulp, Webpack, etc.
function formatValue(value: string): [string, boolean] {
const hasExpandString = /\%[^\%]*\%/i;
return [value.replace(/^[\'\"].*[\'\"]$/, ''), hasExpandString.test(value)];
}
function formatOptions(options: string[]): [string, string, string, boolean] {
let key, value, operator;
switch (options.length) {
case 2:
[key, value] = options;
return [key, '=', ...formatValue(value)];
// ^
// Type 'string | boolean' is not assignable to type 'string'.
// Type 'false' is not assignable to type 'string'.
default:
throw new Error('argument error');
}
}Expected behavior: after destruction of array ts can infer [key, '=', ...formatValue(value)] to be [string, string, string, boolean] with formatValue(string): [string, boolean]
Actual behavior: got error
Type 'string | boolean' is not assignable to type 'string'.
Type 'false' is not assignable to type 'string'.
Related Issues: #5296
micheleangioni, scvnathan, btoo, CaM2091, LennyLip and 6 more
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue