Title: inaccurate string type from json file while resolveJsonModule option on · Issue #27913 · microsoft/TypeScript · GitHub
Open Graph Title: inaccurate string type from json file while resolveJsonModule option on · Issue #27913 · microsoft/TypeScript
X Title: inaccurate string type from json file while resolveJsonModule option on · Issue #27913 · microsoft/TypeScript
Description: TypeScript Version: 3.1.1 VS Code Version: 1.28.1 Search Terms: resolveJsonModule Code ./schema.json { "type": "object" } ./test.ts import schema = require('./schema.json') // give a restriction only the string value 'object' is acceptab...
Open Graph Description: TypeScript Version: 3.1.1 VS Code Version: 1.28.1 Search Terms: resolveJsonModule Code ./schema.json { "type": "object" } ./test.ts import schema = require('./schema.json') // give a restriction on...
X Description: TypeScript Version: 3.1.1 VS Code Version: 1.28.1 Search Terms: resolveJsonModule Code ./schema.json { "type": "object" } ./test.ts import schema = require('./schema.json...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/27913
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"inaccurate string type from json file while resolveJsonModule option on","articleBody":"\u003c!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨\r\n\r\nHalf of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Even if you think you've found a *bug*, please read the FAQ first, especially the Common \"Bugs\" That Aren't Bugs section!\r\n\r\nPlease help us by doing the following steps before logging an issue:\r\n * Search: https://github.com/Microsoft/TypeScript/search?type=Issues\r\n * Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ\r\n\r\nPlease fill in the *entire* template below.\r\n-->\r\n\r\n\u003c!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->\r\n**TypeScript Version:** 3.1.1\r\n**VS Code Version:** 1.28.1\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:** resolveJsonModule\r\n\r\n**Code**\r\n./schema.json\r\n```json\r\n{\r\n \"type\": \"object\"\r\n}\r\n```\r\n./test.ts\r\n```ts\r\nimport schema = require('./schema.json')\r\n// give a restriction only the string value 'object' is acceptable\r\ntype Format = { type: 'object' } \r\n// here the vscode gives the following error\r\n// ; Type { type: string } is not assignable to Format\r\n// ; Type 'string' is not assignable to type ' \"object\" '\r\nconst data: Format = schema \r\n```\r\n\r\n**Expected behavior:**\r\nThe imported string type from json file should be converted as:\r\n\r\nFrom: ``` { type: \"object\" } ```\r\nTo: ``` type FromJson = { type: string & 'object' } ``` \r\n\r\nAs a result, the code below should not be given warnings or errors: \r\n```ts\r\n// imported from json\r\ntype FromJson = { type: string & 'object' }\r\nconst json: FromJson = { type: 'object' }\r\n\r\n// type restriction\r\ntype FromTs = { type: 'object' }\r\n\r\n// no error here\r\nconst ts: FromTs = json\r\n\r\n// no side effect\r\ntype StringType = { type: string }\r\nconst acceptable: StringType = json\r\n```\r\n\r\n**Actual behavior:**\r\nerror on vscode, but pass the compilation\r\n\r\n**Others:**\r\n1\r\nThe typescript 3.03 does not give this error, but it is still not correct because it does not distinguish \r\n```{ type: 'object1' }``` from json and type ```{ type: 'object'}``` from ts code.\r\n2\r\njust considering how to give the type from json file if the string value is very long \r\nthe type ```{ type: string & 'this is a very very very very very very very very long'} ``` seems ugly \r\n\r\n**Related Issues:** Not found\r\n","author":{"url":"https://github.com/baivoom","@type":"Person","name":"baivoom"},"datePublished":"2018-10-15T19:07:42Z","url":"https://github.com/microsoft/TypeScript/issues/27913"}
| 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:2f219486-0dd6-ddf3-ab9c-cc622279c762 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 809A:65478:291F42A:3692EA1:6B01AFC6 |
| html-safe-nonce | 3f60f03093b9a90c5033a9a0f0a4d1af51991d39b3210c0edb75b72acde967bd |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MDlBOjY1NDc4OjI5MUY0MkE6MzY5MkVBMTo2QjAxQUZDNiIsInZpc2l0b3JfaWQiOiI1OTY2NzY0NTA1ODA2NTE2MTY2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 3757ee06ae43e66c636ee2af8f61e77f1403acdb1540714574933b51ed257ba7 |
| hovercard-subject-tag | issue:370302843 |
| 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/27913/issue_layout |
| twitter:image | https://opengraph.githubassets.com/eeaf4d8675eba376d218138c8683414959530dd1bc37307e81753a03920be0b6/microsoft/TypeScript/issues/27913 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/eeaf4d8675eba376d218138c8683414959530dd1bc37307e81753a03920be0b6/microsoft/TypeScript/issues/27913 |
| og:image:alt | TypeScript Version: 3.1.1 VS Code Version: 1.28.1 Search Terms: resolveJsonModule Code ./schema.json { "type": "object" } ./test.ts import schema = require('./schema.json') // give a restriction on... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | baivoom |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width