{"action":"created","comment":{"url":"https://api.github.com/repos/angular-bbs/user-ui/pulls/comments/90589789","pull_request_review_id":11109018,"id":90589789,"diff_hunk":"@@ -0,0 +1,45 @@\n+# 如何引入json文件到typescript\n+\n+## 起因：\n+在ES6/ES205中，你可以import json文件到代码里，例如你创建一个*demo.json*文件\n+```js\n+{\n+  \"name\": \"dapao\"\n+}\n+```\n+然后你就可以在ES6/ES2015中直接导入它\n+```js\n+import * as data from './demo.json';\n+const name = data.name;\n+console.log(name);  //'daopao'\n+```\n+但是在typescript同样的代码会抛出异常\n+```js\n+Cannot find module 'demo.json'\n+```\n+\n+## 解决方案：\n+在typescript2中，我们可以定义自己*.d.ts*[链接](http://www.typescriptlang.org/docs/handbook/namespaces-and-modules.html),如下面\n+```js\n+declare module \"*.json\" {\n+    const value: any;\n+    export default value;\n+}","path":"src/app/_shared/api/articles/231.如何引入json到typescript/_index.md","position":27,"original_position":27,"commit_id":"b7f6fb45efe347e7287cfbee66e9188904ebcff8","original_commit_id":"b7f6fb45efe347e7287cfbee66e9188904ebcff8","user":{"login":"lhtin","id":13173904,"avatar_url":"https://avatars.githubusercontent.com/u/13173904?v=3","gravatar_id":"","url":"https://api.github.com/users/lhtin","html_url":"https://github.com/lhtin","followers_url":"https://api.github.com/users/lhtin/followers","following_url":"https://api.github.com/users/lhtin/following{/other_user}","gists_url":"https://api.github.com/users/lhtin/gists{/gist_id}","starred_url":"https://api.github.com/users/lhtin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lhtin/subscriptions","organizations_url":"https://api.github.com/users/lhtin/orgs","repos_url":"https://api.github.com/users/lhtin/repos","events_url":"https://api.github.com/users/lhtin/events{/privacy}","received_events_url":"https://api.github.com/users/lhtin/received_events","type":"User","site_admin":false},"body":"能否解释一下这段声明代码的用处呢？为什么定义了之后就不会报错了呢？","created_at":"2016-12-02T05:41:35Z","updated_at":"2016-12-02T05:41:35Z","html_url":"https://github.com/angular-bbs/user-ui/pull/53#discussion_r90589789","pull_request_url":"https://api.github.com/repos/angular-bbs/user-ui/pulls/53","_links":{"self":{"href":"https://api.github.com/repos/angular-bbs/user-ui/pulls/comments/90589789"},"html":{"href":"https://github.com/angular-bbs/user-ui/pull/53#discussion_r90589789"},"pull_request":{"href":"https://api.github.com/repos/angular-bbs/user-ui/pulls/53"}}},"pull_request":{"url":"https://api.github.com/repos/angular-bbs/user-ui/pulls/53","id":96082447,"html_url":"https://github.com/angular-bbs/user-ui/pull/53","diff_url":"https://github.com/angular-bbs/user-ui/pull/53.diff","patch_url":"https://github.com/angular-bbs/user-ui/pull/53.patch","issue_url":"https://api.github.com/repos/angular-bbs/user-ui/issues/53","number":53,"state":"open","locked":false,"title":"如何在ts中导入json文件","user":{"login":"btcioner","id":7264584,"avatar_url":"https://avatars.githubusercontent.com/u/7264584?v=3","gravatar_id":"","url":"https://api.github.com/users/btcioner","html_url":"https://github.com/btcioner","followers_url":"https://api.github.com/users/btcioner/followers","following_url":"https://api.github.com/users/btcioner/following{/other_user}","gists_url":"https://api.github.com/users/btcioner/gists{/gist_id}","starred_url":"https://api.github.com/users/btcioner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/btcioner/subscriptions","organizations_url":"https://api.github.com/users/btcioner/orgs","repos_url":"https://api.github.com/users/btcioner/repos","events_url":"https://api.github.com/users/btcioner/events{/privacy}","received_events_url":"https://api.github.com/users/btcioner/received_events","type":"User","site_admin":false},"body":"如何在ts中导入json文件","created_at":"2016-12-01T12:47:51Z","updated_at":"2016-12-02T05:41:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"93e4366b61154b8f254a9dadb88f6d8bada7ac0e","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/angular-bbs/user-ui/pulls/53/commits","review_comments_url":"https://api.github.com/repos/angular-bbs/user-ui/pulls/53/comments","review_comment_url":"https://api.github.com/repos/angular-bbs/user-ui/pulls/comments{/number}","comments_url":"https://api.github.com/repos/angular-bbs/user-ui/issues/53/comments","statuses_url":"https://api.github.com/repos/angular-bbs/user-ui/statuses/b7f6fb45efe347e7287cfbee66e9188904ebcff8","head":{"label":"btcioner:master","ref":"master","sha":"b7f6fb45efe347e7287cfbee66e9188904ebcff8","user":{"login":"btcioner","id":7264584,"avatar_url":"https://avatars.githubusercontent.com/u/7264584?v=3","gravatar_id":"","url":"https://api.github.com/users/btcioner","html_url":"https://github.com/btcioner","followers_url":"https://api.github.com/users/btcioner/followers","following_url":"https://api.github.com/users/btcioner/following{/other_user}","gists_url":"https://api.github.com/users/btcioner/gists{/gist_id}","starred_url":"https://api.github.com/users/btcioner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/btcioner/subscriptions","organizations_url":"https://api.github.com/users/btcioner/orgs","repos_url":"https://api.github.com/users/btcioner/repos","events_url":"https://api.github.com/users/btcioner/events{/privacy}","received_events_url":"https://api.github.com/users/btcioner/received_events","type":"User","site_admin":false},"repo":{"id":72283890,"name":"user-ui","full_name":"btcioner/user-ui","owner":{"login":"btcioner","id":7264584,"avatar_url":"https://avatars.githubusercontent.com/u/7264584?v=3","gravatar_id":"","url":"https://api.github.com/users/btcioner","html_url":"https://github.com/btcioner","followers_url":"https://api.github.com/users/btcioner/followers","following_url":"https://api.github.com/users/btcioner/following{/other_user}","gists_url":"https://api.github.com/users/btcioner/gists{/gist_id}","starred_url":"https://api.github.com/users/btcioner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/btcioner/subscriptions","organizations_url":"https://api.github.com/users/btcioner/orgs","repos_url":"https://api.github.com/users/btcioner/repos","events_url":"https://api.github.com/users/btcioner/events{/privacy}","received_events_url":"https://api.github.com/users/btcioner/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/btcioner/user-ui","description":"Angular BBS的前端，基于Angular 2 + bootstrap 4","fork":true,"url":"https://api.github.com/repos/btcioner/user-ui","forks_url":"https://api.github.com/repos/btcioner/user-ui/forks","keys_url":"https://api.github.com/repos/btcioner/user-ui/keys{/key_id}","collaborators_url":"https://api.github.com/repos/btcioner/user-ui/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/btcioner/user-ui/teams","hooks_url":"https://api.github.com/repos/btcioner/user-ui/hooks","issue_events_url":"https://api.github.com/repos/btcioner/user-ui/issues/events{/number}","events_url":"https://api.github.com/repos/btcioner/user-ui/events","assignees_url":"https://api.github.com/repos/btcioner/user-ui/assignees{/user}","branches_url":"https://api.github.com/repos/btcioner/user-ui/branches{/branch}","tags_url":"https://api.github.com/repos/btcioner/user-ui/tags","blobs_url":"https://api.github.com/repos/btcioner/user-ui/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/btcioner/user-ui/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/btcioner/user-ui/git/refs{/sha}","trees_url":"https://api.github.com/repos/btcioner/user-ui/git/trees{/sha}","statuses_url":"https://api.github.com/repos/btcioner/user-ui/statuses/{sha}","languages_url":"https://api.github.com/repos/btcioner/user-ui/languages","stargazers_url":"https://api.github.com/repos/btcioner/user-ui/stargazers","contributors_url":"https://api.github.com/repos/btcioner/user-ui/contributors","subscribers_url":"https://api.github.com/repos/btcioner/user-ui/subscribers","subscription_url":"https://api.github.com/repos/btcioner/user-ui/subscription","commits_url":"https://api.github.com/repos/btcioner/user-ui/commits{/sha}","git_commits_url":"https://api.github.com/repos/btcioner/user-ui/git/commits{/sha}","comments_url":"https://api.github.com/repos/btcioner/user-ui/comments{/number}","issue_comment_url":"https://api.github.com/repos/btcioner/user-ui/issues/comments{/number}","contents_url":"https://api.github.com/repos/btcioner/user-ui/contents/{+path}","compare_url":"https://api.github.com/repos/btcioner/user-ui/compare/{base}...{head}","merges_url":"https://api.github.com/repos/btcioner/user-ui/merges","archive_url":"https://api.github.com/repos/btcioner/user-ui/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/btcioner/user-ui/downloads","issues_url":"https://api.github.com/repos/btcioner/user-ui/issues{/number}","pulls_url":"https://api.github.com/repos/btcioner/user-ui/pulls{/number}","milestones_url":"https://api.github.com/repos/btcioner/user-ui/milestones{/number}","notifications_url":"https://api.github.com/repos/btcioner/user-ui/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/btcioner/user-ui/labels{/name}","releases_url":"https://api.github.com/repos/btcioner/user-ui/releases{/id}","deployments_url":"https://api.github.com/repos/btcioner/user-ui/deployments","created_at":"2016-10-29T12:37:05Z","updated_at":"2016-10-29T12:37:06Z","pushed_at":"2016-12-01T12:43:43Z","git_url":"git://github.com/btcioner/user-ui.git","ssh_url":"git@github.com:btcioner/user-ui.git","clone_url":"https://github.com/btcioner/user-ui.git","svn_url":"https://github.com/btcioner/user-ui","homepage":"","size":6823,"stargazers_count":0,"watchers_count":0,"language":"TypeScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"angular-bbs:master","ref":"master","sha":"aecef240ec2863d918b8e877019b72956ddbb1cd","user":{"login":"angular-bbs","id":20761270,"avatar_url":"https://avatars.githubusercontent.com/u/20761270?v=3","gravatar_id":"","url":"https://api.github.com/users/angular-bbs","html_url":"https://github.com/angular-bbs","followers_url":"https://api.github.com/users/angular-bbs/followers","following_url":"https://api.github.com/users/angular-bbs/following{/other_user}","gists_url":"https://api.github.com/users/angular-bbs/gists{/gist_id}","starred_url":"https://api.github.com/users/angular-bbs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/angular-bbs/subscriptions","organizations_url":"https://api.github.com/users/angular-bbs/orgs","repos_url":"https://api.github.com/users/angular-bbs/repos","events_url":"https://api.github.com/users/angular-bbs/events{/privacy}","received_events_url":"https://api.github.com/users/angular-bbs/received_events","type":"Organization","site_admin":false},"repo":{"id":65860604,"name":"user-ui","full_name":"angular-bbs/user-ui","owner":{"login":"angular-bbs","id":20761270,"avatar_url":"https://avatars.githubusercontent.com/u/20761270?v=3","gravatar_id":"","url":"https://api.github.com/users/angular-bbs","html_url":"https://github.com/angular-bbs","followers_url":"https://api.github.com/users/angular-bbs/followers","following_url":"https://api.github.com/users/angular-bbs/following{/other_user}","gists_url":"https://api.github.com/users/angular-bbs/gists{/gist_id}","starred_url":"https://api.github.com/users/angular-bbs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/angular-bbs/subscriptions","organizations_url":"https://api.github.com/users/angular-bbs/orgs","repos_url":"https://api.github.com/users/angular-bbs/repos","events_url":"https://api.github.com/users/angular-bbs/events{/privacy}","received_events_url":"https://api.github.com/users/angular-bbs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/angular-bbs/user-ui","description":"Angular BBS的前端，基于Angular 2 + bootstrap 4","fork":false,"url":"https://api.github.com/repos/angular-bbs/user-ui","forks_url":"https://api.github.com/repos/angular-bbs/user-ui/forks","keys_url":"https://api.github.com/repos/angular-bbs/user-ui/keys{/key_id}","collaborators_url":"https://api.github.com/repos/angular-bbs/user-ui/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/angular-bbs/user-ui/teams","hooks_url":"https://api.github.com/repos/angular-bbs/user-ui/hooks","issue_events_url":"https://api.github.com/repos/angular-bbs/user-ui/issues/events{/number}","events_url":"https://api.github.com/repos/angular-bbs/user-ui/events","assignees_url":"https://api.github.com/repos/angular-bbs/user-ui/assignees{/user}","branches_url":"https://api.github.com/repos/angular-bbs/user-ui/branches{/branch}","tags_url":"https://api.github.com/repos/angular-bbs/user-ui/tags","blobs_url":"https://api.github.com/repos/angular-bbs/user-ui/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/angular-bbs/user-ui/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/angular-bbs/user-ui/git/refs{/sha}","trees_url":"https://api.github.com/repos/angular-bbs/user-ui/git/trees{/sha}","statuses_url":"https://api.github.com/repos/angular-bbs/user-ui/statuses/{sha}","languages_url":"https://api.github.com/repos/angular-bbs/user-ui/languages","stargazers_url":"https://api.github.com/repos/angular-bbs/user-ui/stargazers","contributors_url":"https://api.github.com/repos/angular-bbs/user-ui/contributors","subscribers_url":"https://api.github.com/repos/angular-bbs/user-ui/subscribers","subscription_url":"https://api.github.com/repos/angular-bbs/user-ui/subscription","commits_url":"https://api.github.com/repos/angular-bbs/user-ui/commits{/sha}","git_commits_url":"https://api.github.com/repos/angular-bbs/user-ui/git/commits{/sha}","comments_url":"https://api.github.com/repos/angular-bbs/user-ui/comments{/number}","issue_comment_url":"https://api.github.com/repos/angular-bbs/user-ui/issues/comments{/number}","contents_url":"https://api.github.com/repos/angular-bbs/user-ui/contents/{+path}","compare_url":"https://api.github.com/repos/angular-bbs/user-ui/compare/{base}...{head}","merges_url":"https://api.github.com/repos/angular-bbs/user-ui/merges","archive_url":"https://api.github.com/repos/angular-bbs/user-ui/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/angular-bbs/user-ui/downloads","issues_url":"https://api.github.com/repos/angular-bbs/user-ui/issues{/number}","pulls_url":"https://api.github.com/repos/angular-bbs/user-ui/pulls{/number}","milestones_url":"https://api.github.com/repos/angular-bbs/user-ui/milestones{/number}","notifications_url":"https://api.github.com/repos/angular-bbs/user-ui/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/angular-bbs/user-ui/labels{/name}","releases_url":"https://api.github.com/repos/angular-bbs/user-ui/releases{/id}","deployments_url":"https://api.github.com/repos/angular-bbs/user-ui/deployments","created_at":"2016-08-16T23:33:20Z","updated_at":"2016-11-30T05:15:35Z","pushed_at":"2016-12-02T04:55:05Z","git_url":"git://github.com/angular-bbs/user-ui.git","ssh_url":"git@github.com:angular-bbs/user-ui.git","clone_url":"https://github.com/angular-bbs/user-ui.git","svn_url":"https://github.com/angular-bbs/user-ui","homepage":"","size":6802,"stargazers_count":41,"watchers_count":41,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":35,"mirror_url":null,"open_issues_count":11,"forks":35,"open_issues":11,"watchers":41,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/angular-bbs/user-ui/pulls/53"},"html":{"href":"https://github.com/angular-bbs/user-ui/pull/53"},"issue":{"href":"https://api.github.com/repos/angular-bbs/user-ui/issues/53"},"comments":{"href":"https://api.github.com/repos/angular-bbs/user-ui/issues/53/comments"},"review_comments":{"href":"https://api.github.com/repos/angular-bbs/user-ui/pulls/53/comments"},"review_comment":{"href":"https://api.github.com/repos/angular-bbs/user-ui/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/angular-bbs/user-ui/pulls/53/commits"},"statuses":{"href":"https://api.github.com/repos/angular-bbs/user-ui/statuses/b7f6fb45efe347e7287cfbee66e9188904ebcff8"}}}}
{"actor":{"display_login":"lhtin"}}