Title: Excess property checking only applies to half of an intersection · Issue #30715 · microsoft/TypeScript · GitHub
Open Graph Title: Excess property checking only applies to half of an intersection · Issue #30715 · microsoft/TypeScript
X Title: Excess property checking only applies to half of an intersection · Issue #30715 · microsoft/TypeScript
Description: TypeScript Version: 3.3.333 Search Terms: Type infer array nested interface structure Code interface ValueOnly { value: number | null; } interface ValueAndKey { key: string | null; value: number | null; } interface ValueOnlyFields { fiel...
Open Graph Description: TypeScript Version: 3.3.333 Search Terms: Type infer array nested interface structure Code interface ValueOnly { value: number | null; } interface ValueAndKey { key: string | null; value: number | ...
X Description: TypeScript Version: 3.3.333 Search Terms: Type infer array nested interface structure Code interface ValueOnly { value: number | null; } interface ValueAndKey { key: string | null; value: number | ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/30715
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Excess property checking only applies to half of an intersection","articleBody":"**TypeScript Version:** 3.3.333\r\n\r\n**Search Terms:**\r\nType infer array nested interface structure\r\n\r\n**Code**\r\n\r\n```ts\r\ninterface ValueOnly {\r\n value: number | null;\r\n}\r\n\r\ninterface ValueAndKey {\r\n key: string | null;\r\n value: number | null;\r\n}\r\n\r\ninterface ValueOnlyFields {\r\n fields: Array\u003cValueOnly>;\r\n}\r\n\r\ninterface ValueAndKeyFields {\r\n fields: Array\u003cValueAndKey>;\r\n}\r\n\r\ninterface BugRepro {\r\n dataType: ValueAndKeyFields & ValueOnlyFields;\r\n}\r\n\r\ninterface BugReproWithoutArray {\r\n dataType: ValueAndKey & ValueOnly;\r\n}\r\n\r\n// This. Having the \"key\" errors out because of extra \"key\" field,\r\n// while not having the \"key\" makes it complain that \"key\" is missing.\r\nconst repro: BugRepro = {\r\n dataType: {\r\n fields: [{\r\n key: 'bla',\r\n value: null,\r\n }],\r\n }\r\n}\r\n\r\n// Without nesting the type inside of an array, it can infer the type nicely.\r\nconst reproWithoutArray: BugReproWithoutArray = {\r\n dataType: {\r\n key: 'bla',\r\n value: null,\r\n },\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\nCompiler should not complain that \"key\" is defined.\r\n\r\n**Actual behavior:**\r\nCompiler cannot identify that the array is neither Array\u003cValueAndKey>, and Array\u003cValueOnly> without me casting it.\r\n\r\n**Playground Link:**\r\nhttps://www.typescriptlang.org/play/#src=interface%20ValueOnly%20%7B%0D%0A%20%20value%3A%20number%20%7C%20null%3B%0D%0A%7D%0D%0A%0D%0Ainterface%20ValueAndKey%20%7B%0D%0A%20%20key%3A%20string%20%7C%20null%3B%0D%0A%20%20value%3A%20number%20%7C%20null%3B%0D%0A%7D%0D%0A%0D%0Ainterface%20ValueOnlyFields%20%7B%0D%0A%20%20fields%3A%20Array%3CValueOnly%3E%3B%0D%0A%7D%0D%0A%0D%0Ainterface%20ValueAndKeyFields%20%7B%0D%0A%20%20fields%3A%20Array%3CValueAndKey%3E%3B%0D%0A%7D%0D%0A%0D%0Ainterface%20BugRepro%20%7B%0D%0A%20%20dataType%3A%20ValueAndKeyFields%20%26%20ValueOnlyFields%3B%0D%0A%7D%0D%0A%0D%0Ainterface%20BugReproWithoutArray%20%7B%0D%0A%20%20dataType%3A%20ValueAndKey%20%26%20ValueOnly%3B%0D%0A%7D%0D%0A%0D%0A%2F%2F%20This.%20Having%20the%20%22key%22%20errors%20out%20because%20of%20extra%20%22key%22%20field%2C%0D%0A%2F%2F%20while%20not%20having%20the%20%22key%22%20makes%20it%20complain%20that%20%22key%22%20is%20missing.%0D%0Aconst%20repro%3A%20BugRepro%20%3D%20%7B%0D%0A%20%20dataType%3A%20%7B%0D%0A%20%20%20%20fields%3A%20%5B%7B%0D%0A%20%20%20%20%20%20key%3A%20'bla'%2C%0D%0A%20%20%20%20%20%20value%3A%20null%2C%0D%0A%20%20%20%20%7D%5D%2C%0D%0A%20%20%7D%0D%0A%7D%0D%0A%0D%0Aconst%20reproWithoutArray%3A%20BugReproWithoutArray%20%3D%20%7B%0D%0A%20%20dataType%3A%20%7B%0D%0A%20%20%20%20key%3A%20'bla'%2C%0D%0A%20%20%20%20value%3A%20null%2C%0D%0A%20%20%7D%2C%0D%0A%7D%0D%0A%0D%0A\r\n\r\n**Related Issues:**\r\nCouldn't find.\r\n","author":{"url":"https://github.com/brunostuani","@type":"Person","name":"brunostuani"},"datePublished":"2019-04-02T17:53:17Z","url":"https://github.com/microsoft/TypeScript/issues/30715"}
| 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:770fbdf0-8955-c7ab-d7ab-581a99561092 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E7BC:DA744:B19128:EF7F66:6B00F721 |
| html-safe-nonce | 4a01e0c4d8c8caf53862bf8e70be58145b5729043f185f9911b912d11be7cb4f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFN0JDOkRBNzQ0OkIxOTEyODpFRjdGNjY6NkIwMEY3MjEiLCJ2aXNpdG9yX2lkIjoiNDU4ODI0NDY0NjA0Mzk1Mjk3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | d267dc6ce1caec9953c85b086b29e54ff2c75ed7585dcbbbd1638e78979fc74b |
| hovercard-subject-tag | issue:428362371 |
| 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/30715/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1aa9acd2827f27bfeff6a425f8151a0908f5640846c5e6aa50e049c4eec14e4b/microsoft/TypeScript/issues/30715 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1aa9acd2827f27bfeff6a425f8151a0908f5640846c5e6aa50e049c4eec14e4b/microsoft/TypeScript/issues/30715 |
| og:image:alt | TypeScript Version: 3.3.333 Search Terms: Type infer array nested interface structure Code interface ValueOnly { value: number | null; } interface ValueAndKey { key: string | null; value: number | ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | brunostuani |
| 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