Skip to content

Instantly share code, notes, and snippets.

@blefebvre
Last active June 11, 2020 10:41
Show Gist options
  • Save blefebvre/ee3e6f90390119529b89cea166236984 to your computer and use it in GitHub Desktop.
Save blefebvre/ee3e6f90390119529b89cea166236984 to your computer and use it in GitHub Desktop.
Types in JS
// Examples of types in JS
let count = 1;
console.log(typeof count); // number
count = "1";
console.log(typeof count); // string
count = {count: 1};
console.log(typeof count); // object
count = () => 1;
console.log(typeof count); // function
count = [1];
console.log(typeof count); // object
// Type inferrence with TS. React examples
// Start at level 1
const [level, setLevel] = useState(1);
// Overlay which shows "Game over"
const [showGameOver, setShowGameOver] = useState(false);
// The shapes, ordered by how they will appear. This is empty until "Go" is clicked
const [shapes, setShapes] = useState<Shape[]>([]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment