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 — Const indexed access issue — should attempt widening to a mapped type · Issue #51156 · 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 DescriptionBug ReportAnders Hejlsberg (@ahejlsberg) This issue seems nearly identical to #47368, but this time for const object types which are assignable to the mapped type. 🔎 Search Termsconst indexed access; object literal indexed access; object literal widen; widen mapped type 🕗 Version & Regression Information
⏯ Playground LinkPlayground link with relevant code 💻 Codetype ArgMap = { a: number, b: string }; type Func<K extends keyof ArgMap> = (x: ArgMap[K]) => void; type Funcs = { [K in keyof ArgMap]: Func<K> }; const funcs = { a: (x: number) => {}, b: (x: string) => {}, }; function f1<K extends keyof ArgMap>(key: K, arg: ArgMap[K]) { funcs[key](arg); } function f2<K extends keyof ArgMap>(key: K, arg: ArgMap[K]) { const func = funcs[key]; // Type Funcs[K] func(arg); } function f3<K extends keyof ArgMap>(key: K, arg: ArgMap[K]) { const func: Func<K> = funcs[key]; // Error, Funcs[K] not assignable to Func<K> func(arg); } 🙁 Actual behaviorUnexpected error in example above. It's unexpected because throwing away type information makes this type check correctly, by widening with either 🙂 Expected behaviorNo errors in example above. 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. |