mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-23 07:07:09 -05:00
Remove undefined from optional properties when inferring to index signatures (#43086)
* Remove undefined from optional properties when inferring to index signatures * Add tests
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
// @strict: true
|
||||
// @target: esnext
|
||||
|
||||
declare function foo<T>(obj: { [x: string]: T }): T;
|
||||
|
||||
declare const x1: { a: string, b: number };
|
||||
declare const x2: { a: string, b: number | undefined };
|
||||
declare const x3: { a: string, b?: number };
|
||||
declare const x4: { a: string, b?: number | undefined };
|
||||
|
||||
let a1 = foo(x1); // string | number
|
||||
let a2 = foo(x2); // string | number | undefined
|
||||
let a3 = foo(x3); // string | number
|
||||
let a4 = foo(x4); // string | number
|
||||
|
||||
// Repro from #43045
|
||||
|
||||
const param2 = Math.random() < 0.5 ? 'value2' : null;
|
||||
|
||||
const obj = {
|
||||
param1: 'value1',
|
||||
...(param2 ? {param2} : {})
|
||||
};
|
||||
|
||||
const query = Object.entries(obj).map(
|
||||
([k, v]) => `${k}=${encodeURIComponent(v)}`
|
||||
).join('&');
|
||||
Reference in New Issue
Block a user