This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export function sayHello(name: string): string { | |
| return `Hello, ${name}`; | |
| } | |
| /* | |
| NOTE: this is the compiled JavaScript, assuming CommonJS module format | |
| "use strict"; | |
| function sayHello(name) { | |
| return "Hello, " + name; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace InternalModule { | |
| export function add(...args: number[]): number { | |
| return args.reduce((acc, cur) => acc + cur, 0); | |
| } | |
| } | |
| export = InternalModule; | |
| /* | |
| NOTE: this is the compiled JavaScript, assuming CommonJS module format |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as SomeModule from "./module1"; | |
| import * as AnotherModule from "./module2"; | |
| console.log(SomeModule.sayHello("Willson")); | |
| console.log(AnotherModule.add(1, 2, 3, 4)); | |
| /* | |
| NOTE: this is the compiled JavaScript, assuming CommonJS module format | |
| "use strict"; | |
| var SomeModule = require("./module1"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>Typescript Modules</title> | |
| </head> | |
| <body> | |
| <script src="build/bundle.js"></script> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This uses JSX syntax. | |
| var helloWorld = <div>Hello World!</div>; | |
| // And this is what the JSX syntax compiles into in JavaScript: | |
| var helloWorld = React.createElement( | |
| "div", | |
| null, | |
| "Hello World!" | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Here's a React Component class | |
| class CustomForm extends React.Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { | |
| inputText: "Willson" | |
| }; | |
| this.handleInputChange = this.handleInputChange.bind(this); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Here's a React Component class | |
| class CustomForm extends React.Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { | |
| inputText: "Willson" | |
| }; | |
| this.handleInputChange = this.handleInputChange.bind(this); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Actions are plain old JavaScript objects. They adhere to particular | |
| * interface in that they must have a "type" property, but aside from | |
| * that, you can add any other property you want. | |
| */ | |
| const FREE_THROW = "FREE_THROW"; | |
| const TWO_POINT_SHOT = "TWO_POINT_SHOT"; | |
| // an example Action |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // PSEUDO CODE BELOW | |
| import { createStore } from "redux"; | |
| const team1Hoop = createStore( /* ignore the arguments here for now */ ); | |
| /* | |
| * The store created above manages your entire application's state. | |
| * You can think of the store as containing a giant JavaScript object | |
| * where each key is a particular piece of the application state and |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const team1Hoop = createStore( /* ignore the arguments here for now */ ); | |
| const twoPointer = { | |
| type: TWO_POINT_SHOT, | |
| payload: { | |
| points: 2 | |
| } | |
| }; | |
| /* |