Closed
Description
TypeScript Version: typescript@3.4.0-dev.20190202
Search Terms:
set union constructor strict null undefined readonly array strictNullChecks
Code
const params = undefined as Set<any> | undefined;
const ok = params ? new Set(params) : new Set(params);
const ng = new Set(params);
compile command
tsc test.ts -target ES2017 -strict
Expected behavior:
It should be compiled successfully
Actual behavior:
Line const ng = new Set(params)
raise type error:
error TS2345: Argument of type 'Set<any> | undefined' is not assignable to parameter of type 'readonly any[] | null | undefined'.
Type 'Set<any>' is missing the following properties from type 'readonly any[]': length, concat, join, slice, and 11 more.
This error occurs only when strictNullChecks is enabled
Playground Link:
http://www.typescriptlang.org/play/#src=const%20params%20%3D%20undefined%20as%20Set%3Cany%3E%20%7C%20undefined%3B%0D%0Aconst%20ok%20%3D%20params%20%3F%20new%20Set(params)%20%3A%20new%20Set(params)%3B%0D%0Aconst%20ng%20%3D%20new%20Set(params)%3B%0D%0A
Toggle strictNullChecks on/off from "Option" menu
Related Issues:
I could not find any related issues.