This file contains 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 React from 'react'; | |
function App() { | |
const canvasRef = React.useRef<HTMLCanvasElement>(null); | |
const [context, setContext] = React.useState<CanvasRenderingContext2D | null>(null); | |
React.useEffect(() => { | |
}, [context]); |
This file contains 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 upperCaseFirst(inputStr) { | |
var valueOfFirstChar = inputStr.charCodeAt(0); | |
console.log('Value of first character:', valueOfFirstChar); | |
var upperCaseLetter = String.fromCharCode(valueOfFirstChar - 32); | |
console.log('Uppercase first character:', upperCaseLetter); | |
var restOfString = inputStr.slice(1); | |
console.log('Rest of the string:', restOfString); |
This file contains 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 os from 'os'; | |
const cpuInfo = os.cpus(); | |
console.log(cpuInfo); |
This file contains 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 React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import './index.css'; | |
import App from './App'; | |
import * as serviceWorker from './serviceWorker'; | |
ReactDOM.render(<App name={"TypeScript Master"} />, document.getElementById('root')); | |
// If you want your app to work offline and load faster, you can change | |
// unregister() to register() below. Note this comes with some pitfalls. |
This file contains 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 React from 'react'; | |
import logo from './logo.svg'; | |
import './App.css'; | |
interface AppProps { | |
name: string | |
} | |
const App: React.FC<AppProps> = ({ name }) => { | |
return ( |
This file contains 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
// Basic types | |
var trueOrFalse: boolean; | |
var quantity: number; | |
var message: string; | |
var doNotKnowYet: undefined; | |
var nothingness: null; | |
var iCanBeAnything: any; // this is self-defeating! | |
// Typed arrays | |
var arrayOfStrings: string[]; |
This file contains 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
{ | |
"name": "from-js-to-ts", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1", | |
"build:dev": "tsc --watch --preserveWatchOutput", | |
"start": "node dist/index.js" | |
}, |
This file contains 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
"scripts": { | |
"start:dev": "nodemon dist/index.js", | |
"build:dev": "tsc --watch --preserveWatchOutput", | |
"dev": "concurrently \"npm:build:dev\" \"npm:start:dev\"", | |
"postinstall": "tsc", | |
"start": "node dist/index.js" | |
}, |
This file contains 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 { DS } from './node'; | |
export class LinkedList<T> { | |
private head: DS.Node<T>; | |
private tail: DS.Node<T>; | |
constructor() { | |
this.head = new DS.Node<T>(); | |
this.tail = new DS.Node<T>(); | |
this.head.next = this.tail; |
This file contains 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 { LinkedList } from '../linked_list/linked_list'; | |
export class StackList<T> { | |
private list: LinkedList<T>; | |
public constructor() { | |
this.list = new LinkedList<T>(); | |
} | |
public isEmpty(): boolean { |