Closed
Description
TypeScript Version: 3.4.0-dev.201xxxxx
Search Terms:
npx tsc --version
: Version 3.7.0-dev.20191003
Code
Run with npx tsc index.ts --out index.js --noImplicitAny --strictNullChecks
type TestType = 'blah' | number;
const testObjects = [
{test: undefined, str: 'foo'},
{test: 42, str: 'bar'}
] as {test: TestType, str: string}[]; // Why is this not an error?
const obj1: TestType = undefined; // Type 'undefined' is not assignable to type 'TestType'.
const obj2 = undefined as TestType; // Conversion of type 'undefined' to type 'TestType' may be a mistake because neither type sufficiently overlaps with the other.
Expected behavior:
This should be an error
const testObjects = [
{test: undefined, str: 'foo'},
{test: 42, str: 'bar'}
] as {test: TestType, str: string}[];
Something in the lines of Conversion of type 'type1' to type 'type2' may be a mistake because neither type sufficiently overlaps with the other.
Actual behavior:
This compiles without errors:
const testObjects = [
{test: undefined, str: 'foo'},
{test: 42, str: 'bar'}
] as {test: TestType, str: string}[];
Playground Link:
Related Issues: