Closed
Description
Bug Report
🔎 Search Terms
mapped, generic, string, union
🕗 Version & Regression Information
- This is the behavior in every version I tried. (I tried every version the Typescript Playground has listed, and didn't see a pertinent answer in the FAQ)
⏯ Playground Link
Playground link with relevant code
💻 Code
// API Types
type NewParameters<EndpointParameters = never> = { [key in keyof EndpointParameters]: (NonNullable<EndpointParameters[key]>)[] };
// Test type v1
interface TestV1 {
foo: 'foo' | 'bar' | 'baz';
}
// Test type v2
interface Split1 {
foo: 'foo';
}
interface Split2 {
foo: 'bar';
}
interface Split3 {
foo: 'baz';
}
type TestV2 = Split1 | Split2 | Split3;
// Tests
// This throws an error
const test1: NewParameters<TestV2> = { foo: ['baz', 'foo', 'bar'] };
// These do not
const test2: { [key in keyof TestV2]: (NonNullable<TestV2[key]>)[] } = { foo: ['baz', 'foo', 'bar'] };
const test3: NewParameters<TestV1> = { foo: ['baz', 'foo', 'bar'] };
🙁 Actual behavior
Test examples 1 and 2 produce different types.
🙂 Expected behavior
Behavior should be consistent between the first two test examples.