-
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: Nightly
Search Terms: tuple intersection array
Expected behavior:
Expected code to compile. It does compile with tsc 3.8, but does not compile with tsc 3.9 (Nightly).
Actual behavior:
In the code below, the following error is reported:
const x: [number, ...number[]]
Type 'number[] & [number, ...number[]]' is not assignable to type '[number, ...number[]]'.(2322)Code
const y: number[] & [number, ...number[]] = [1];
const x: [number, ...number[]] = y;Discussion
Presumably, this is related to the breaking change in 3.9 around handling of tuple types more strictly. I believe the code is correct however and should compile, because the array type number[] is a strict supertype of the tuple type [number, ...number[]] (surely?) - perhaps the special case unifying tuple types with matching element types to an array type hasn't been implemented?
Discovered by @JasonGore and @NWilson (MSFT).
Output
"use strict";
const y = [1];
const x = y;Compiler Options
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"strictBindCallApply": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"useDefineForClassFields": false,
"alwaysStrict": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"downlevelIteration": false,
"noEmitHelpers": false,
"noLib": false,
"noStrictGenericChecks": false,
"noUnusedLocals": false,
"noUnusedParameters": false,
"esModuleInterop": true,
"preserveConstEnums": false,
"removeComments": false,
"skipLibCheck": false,
"checkJs": false,
"allowJs": false,
"declaration": true,
"experimentalDecorators": false,
"emitDecoratorMetadata": false,
"target": "ES2017",
"module": "ESNext"
}
}Playground Link: Provided
Reactions are currently unavailable
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