Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Can assign types even though interface field overriden using Omit #36604

Copy link
Copy link

Description

@tom-thorne
Issue body actions

TypeScript Version: 3.7.5

Search Terms:

Omit field override intersection assign missing error

Expected behavior:

If I use Omit and an intersection to override a field within an interface, when I assign an object of new type to original type I am expecting that typescript would give an error.

For example, in the example below, I expect to see a compile error in the line x = v;
But unfortunately there isn't.

However, assigning the field explicitly between the 2 types does give an error.

Playground Link: Provided

Actual behavior:

Code

interface To {
  field?: number;
  anotherField: string;
}

type From =  { field: null } & Omit<To, 'field'>

function foo(v: From) {
  let x: To;
  x = v;  // expect to have an error but there isn't
  x.field = v.field; // Type 'null' is not assignable to type 'number | undefined'
}
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"
  }
}
Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

Breaking ChangeWould introduce errors in existing codeWould introduce errors in existing codeBugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

Morty Proxy This is a proxified and sanitized view of the page, visit original site.