GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Exclude in typescript behaves differently when substitute with its definition · Issue #60973 · microsoft/TypeScript 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🔎 Search Termssite:github.com/microsoft/TypeScript Exclude 🕗 Version & Regression Information
⏯ Playground Link💻 Codetype _Exclude<T, U> = T extends U ? never : T; type MyType1 = 1 | 2 | 3 | 4 type MyType2 = 3 | 4 | 5 | 6 type Result1 = _Exclude<MyType1, MyType2> // 1 | 2 type Result2 = MyType1 extends MyType2 ? never : MyType1 // 1 | 2 | 3 | 4 type Result3 = [MyType1] extends MyType2 ? never : MyType1 // 1 | 2 | 3 | 4 // Maybe an improvement for non-generic cases? type Result4 = [K in MyType1] extends MyType2 ? never : K // ERROR 🙁 Actual behaviorUsing "Distributive Conditional Types" in a generic type behaves differently compared to using concrete types. (Not Referential transparent) 🙂 Expected behavior"Distributive Conditional Types" always works the same, no matter if it is being used in generic types or not. Additional information about the issueIf "Distributive Conditional Types" should behave differently, I believe it worth providing a way for non-generic types to be able to distribute over the union type in conditional types, same as how it works in generics. Maybe having a syntax like: type MyType1 = 1 | 2 | 3 | 4 type MyType2 = 3 | 4 | 5 | 6 type Result4 = [K in MyType1] extends MyType2 ? never : K Activity
MetadataMetadataAssigneesLabelsWorking as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug TypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |