-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
TypeScript Version: Nightly
Search Terms:
Type Union, Type check during assignment
Expected behavior:
Some error i.e.
19:7 - error TS2339: Property 'c' does not exist on type 'tAB'.
19 c: false,
Actual behavior:
exits with status 0
Related Issues:
Code
type tAB = {
a: string
b: number
}
type tAC = {
a: string
c: boolean
}
type tUnion = tAB | tAC
//@ts-ignore Type '{}' is not assignable to type 'tUnion'
const empty: tUnion = {}
//No ts-error but should be
const union: tUnion = {
a: '',
b: 0,
c: false,
}
//@ts-ignore Property 'b' does not exist on type 'tAC'
union.b
Output
"use strict";
//@ts-ignore Type '{}' is not assignable to type 'tUnion'
const empty = {};
//No ts-error but should be
const union = {
a: '',
b: 0,
c: false,
};
//@ts-ignore Property 'b' does not exist on type 'tAC'
union.b;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
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug