{"id":3928,"date":"2016-04-30T01:20:52","date_gmt":"2016-04-30T01:20:52","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=3928"},"modified":"2016-04-30T01:20:52","modified_gmt":"2016-04-30T01:20:52","slug":"fixing-typescript-error-error-ts2304-cannot-find-name-react","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/fixing-typescript-error-error-ts2304-cannot-find-name-react\/","title":{"rendered":"Fixing Typescript error:  error TS2304: Cannot find name &#8216;React&#8217;."},"content":{"rendered":"<p>If you try to do an import in Typescript, you can get an error like this:<\/p>\n<pre>\nindex.tsx(10,25): error TS2304: Cannot find name 'React'.\n<\/pre>\n<p>In order to do an import successfully, you probably did something like below, or set up tsconfig.json (either should work):<\/p>\n<pre>\n\/\/\/ <reference path=\"typings\/main\/definitions\/react\/index.d.ts\" \/>\n<\/pre>\n<p>When you write the Javascript code, it should look similar to the following:<\/p>\n<pre lang=\"javascript\">\nGarys-MBP:youtube gary$ cat app\/index.tsx\nimport * as React from 'react';\n\ninterface IMessage {\n  msg: String;\n}\n\nclass TestApp extends React.Component<IMessage, {}> {\n  public render(): Element {\n    return <div>test<\/div>;\n  }\n}\n<\/pre>\n<p>If you&#8217;re receiving the above error, the most likely cause is that you have a case-sensitivity issue: either you&#8217;re alternating case in Javascript class names, or you installed &#8220;React&#8221; with npm but reference it as &#8220;react&#8221; in your import (make sure you are consistent within your project, or this will fail hard)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Fixing a really frustrating compilation error importing React into a Typescript project<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[9],"tags":[302,455,557],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/3928"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=3928"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/3928\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=3928"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=3928"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=3928"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}