Title: Allow property (dotted) access syntax for types with string index signatures · Issue #12596 · microsoft/TypeScript · GitHub
Open Graph Title: Allow property (dotted) access syntax for types with string index signatures · Issue #12596 · microsoft/TypeScript
X Title: Allow property (dotted) access syntax for types with string index signatures · Issue #12596 · microsoft/TypeScript
Description: It doesn't make much sense to forbid property access (o.unknown) syntax on a type with a string index signature, but allow element access syntax (o['unknown']). Note that this should only apply to types with an explicit string index sign...
Open Graph Description: It doesn't make much sense to forbid property access (o.unknown) syntax on a type with a string index signature, but allow element access syntax (o['unknown']). Note that this should only apply to ...
X Description: It doesn't make much sense to forbid property access (o.unknown) syntax on a type with a string index signature, but allow element access syntax (o['unknown']). Note that this should on...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/12596
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Allow property (dotted) access syntax for types with string index signatures","articleBody":"It doesn't make much sense to forbid property access (`o.unknown`) syntax on a type with a string index signature, but allow element access syntax (`o['unknown']`).\r\n\r\nNote that this should only apply to types with an *explicit* string index signature — element access is currently allowed on any type if you don't pass `--noImplicitAny`, but this should not be true for property access.\r\n\r\n**Given**\r\n\r\n```ts\r\ntype Flags = {\r\n aLongName: boolean;\r\n anotherReallyLongOne: number;\r\n someOtherOnes: boolean;\r\n [other: string]: number | boolean;\r\n}\r\n``` \r\n\r\n**Expected behavior:**\r\n\r\n```ts\r\nfunction f(flags: Flags) {\r\n flags.aLongName; // ok\r\n flags.anUnknownName; // ok\r\n flags.aLongname; // ok, but misspelled\r\n flags['aLongName']; // ok\r\n flags['anUnknownName']; // ok\r\n flags['aLongname']; // ok, but misspelled\r\n}\r\n```\r\n\r\n**Actual behavior:**\r\n\r\n```ts\r\nfunction f(flags: Flags) {\r\n flags.aLongName; // ok\r\n flags.anUnknownName; // error, unknown\r\n flags.aLongname; // error, misspelled\r\n flags['aLongName']; // ok\r\n flags['anUnknownName']; // ok\r\n flags['aLongname']; // ok, but misspelled\r\n}\r\n```","author":{"url":"https://github.com/sandersn","@type":"Person","name":"sandersn"},"datePublished":"2016-12-01T01:32:15Z","url":"https://github.com/microsoft/TypeScript/issues/12596"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:c58e48a9-29d0-0cbe-63fb-c576527977a8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DC6C:1CFBF7:26EEC:30E5B:6B00F0E6 |
| html-safe-nonce | a801d2c6e0d7636391a7c7558ba575b84909f085abd3f9d4c3cc06453b525dcb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQzZDOjFDRkJGNzoyNkVFQzozMEU1Qjo2QjAwRjBFNiIsInZpc2l0b3JfaWQiOiIxMzg0ODA3MzI3NTg0MDIyNzU4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | d51afa8f4fee7c5b7cc39d27dac18ce6ec2f758f8985731f218eabdc5d62f692 |
| hovercard-subject-tag | issue:192731294 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/12596/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b75bed9efae12438d65859757e73c0b27f3b8dca6449fb0abb1bd63ac799adee/microsoft/TypeScript/issues/12596 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b75bed9efae12438d65859757e73c0b27f3b8dca6449fb0abb1bd63ac799adee/microsoft/TypeScript/issues/12596 |
| og:image:alt | It doesn't make much sense to forbid property access (o.unknown) syntax on a type with a string index signature, but allow element access syntax (o['unknown']). Note that this should only apply to ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sandersn |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width