Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save davidystephenson/6d098336a7a9fc1947baa25820b5ea3c to your computer and use it in GitHub Desktop.
Save davidystephenson/6d098336a7a9fc1947baa25820b5ea3c to your computer and use it in GitHub Desktop.
enum Subject {
Js = 'JavaScript',
Html = 'Hyper Text Markup Language',
Css = 'Cascading Style Sheets',
React = 'React'
}
function describeLearning (subject: Subject) {
console.log('Today I learned about:', subject)
}
describeLearning(Subject.Js)
String()
Number()
class Car {
}
const car = new Car()
type Stuff = string | number
type StuffOrBoolean = Stuff | boolean
type Player = [jersey: number, first: string, last: string, drafted: boolean]
interface Trip { start: string, end: string, budget: number }
interface Cruise extends Trip { boat: string }
const cruise: Cruise = {
start: 'a',
end: 'b',
budget: 2000,
boat: 'c'
}
// console.log(Stuff)
// Union
const random = Math.random()
// const result = random > 0.5 ? 'hello' : 42
const x = 1
const numbers = [1, 2, 3]
const stuff = ['a', 'b', 'c', 1, x]
const tuple: Player = [1, 'dorothy', 'parker', true]
const trip = {
start: 'NYC',
end: 'Johannesburg',
budget: 1000
}
function describeTrip (trip: Trip) {
console.log('Your trip will start in:', trip.start)
console.log('Your trip will end in:', trip.end)
if (trip.budget > 5000) {
console.log('Your trip is too expensive!')
} else {
console.log('Your trip is affordable... barely...')
}
}
describeTrip(trip)
function announcePick (player: Player) {
const nextNumber = player[0] + 1
const uppercaseName = player[1].toUpperCase()
}
announcePick(tuple)
function add (a: string , b: string) {
// 1 + 1 === 2
// '1' + '1' === '11'
return a.length + b.length
}
const result = add('hello', 'hi')
console.log(result)
function something (x: string) {
}
something(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment