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
// 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
<!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
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
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
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Typescript Modules</title> | |
</head> | |
<body> | |
<script src="build/module1.js"></script> | |
<script src="build/module2.js"></script> | |
<script src="build/app.js"></script> |
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
console.log(sayHello("Willson")); | |
console.log(InternalModule.add(1, 2, 3, 4)); |
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); | |
} | |
} |
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
function sayHello(name: string): string { | |
return `Hello, ${name}`; | |
} |