IssueRaiser

Suggestion: perform excess property checks when spreading an inline object literal

<!-- 🚨 STOP 🚨 STOP 🚨 STOP 🚨 Half of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Even if you think you've found a *bug*, please read the FAQ first, especially the Common "Bugs" That Aren't Bugs section! Please help us by doing the following steps before logging an issue: * Search: https://github.com/Microsoft/TypeScript/search?type=Issues * Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ Please fill in the *entire* template below. --> <!-- Please try to reproduce the issue with the latest published version. It may have already been fixed. For npm: `typescript@next` This is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly --> **TypeScript Version:** 3.9.2 <!-- Search terms you tried before logging this (so others can find this issue more easily) --> **Search Terms:** **Code** ```ts declare const someCondition: boolean; type MyObject = { foo: number; bar?: number }; const a: MyObject = { foo: 1, bar: 2, // βœ… Error because `invalid` is an excess property invalid: 3, }; const b: MyObject = { foo: 1, ...(someCondition ? { bar: 2, // ❌ `invalid` is an excess property, but we don't get an error here invalid: 3, } : {}), }; ``` In the example above, I only want to include specific properties when a condition is met. That's the only reason I'm using spread here. I understand that TypeScript only performs

Posted by OliverJAsh on Aug 11, 2020, 3:18 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.3,000 issues0 comments

github (Software)

Suggestion: perform excess property checks when spreading an inline object literal

OliverJAshAug 11, 2020, 3:18 PM

<!-- 🚨 STOP 🚨 STOP 🚨 STOP 🚨 Half of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Even if you think you've found a *bug*, please read the FAQ first, especially the Common "Bugs" That Aren't Bugs section! Please help us by doing the following steps before logging an issue: * Search: https://github.com/Microsoft/TypeScript/search?type=Issues * Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ Please fill in the *entire* template below. --> <!-- Please try to reproduce the issue with the latest published version. It may have already been fixed. For npm: `typescript@next` This is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly --> **TypeScript Version:** 3.9.2 <!-- Search terms you tried before logging this (so others can find this issue more easily) --> **Search Terms:** **Code** ```ts declare const someCondition: boolean; type MyObject = { foo: number; bar?: number }; const a: MyObject = { foo: 1, bar: 2, // βœ… Error because `invalid` is an excess property invalid: 3, }; const b: MyObject = { foo: 1, ...(someCondition ? { bar: 2, // ❌ `invalid` is an excess property, but we don't get an error here invalid: 3, } : {}), }; ``` In the example above, I only want to include specific properties when a condition is met. That's the only reason I'm using spread here. I understand that TypeScript only performs

Comments (0)

No comments yet. Start the discussion.

Comment on this issue