Created
November 19, 2018 04:39
-
-
Save dpashkevich/5e0e08a6009665294210bdadf1bf3318 to your computer and use it in GitHub Desktop.
Gists for article "7 outdated excuses to avoid TypeScript"
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
declare function camelize(s: string): string; |
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 greeter(person) { | |
if (!person || !person.firstName || !person.lastName) { | |
throw new Error('invalid arguments'); | |
} | |
return "Hello, " + person.firstName + " " + person.lastName; | |
} | |
// Jasmine spec: | |
describe("greeter", function() { | |
it("returns greeting on valid input", function() { | |
expect( | |
greeter({firstName: 'James', lastName: 'Hetfield'}) | |
).toEqual('Hello, James Hetfield'); | |
}); | |
it("throws on invalid input", function() { | |
expect(() => greeter()).toThrowError('invalid arguments'); | |
expect(() => greeter(5)).toThrowError('invalid arguments'); | |
expect(() => greeter({firstName: 'Jason'})).toThrowError('invalid arguments'); | |
}); | |
}); |
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
let user = { firstName: "James", lastName: "Hetfield" }; | |
console.log(greeter(user)); |
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 greeter(person) { | |
return "Hello, " + person.firstName + " " + person.lastName; | |
} |
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
interface Person { | |
firstName: string; | |
lastName: string; | |
} | |
function greeter(person: Person) { | |
return "Hello, " + person.firstName + " " + person.lastName; | |
} | |
// Jasmine spec: | |
describe("greeter", function() { | |
it("returns greeting", function() { | |
expect( | |
greeter({firstName: 'James', lastName: 'Hetfield'}) | |
).toEqual('Hello, James Hetfield'); | |
}); | |
}); |
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
class Greeter { | |
constructor(message) { | |
this.greeting = message; | |
} | |
greet() { | |
return "Hello, " + this.greeting; | |
} | |
} |
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
class Greeter { | |
greeting: string; | |
constructor(message: string) { | |
this.greeting = message; | |
} | |
greet() { | |
return "Hello, " + this.greeting; | |
} | |
} |
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
npm install --save-dev @types/jasmine |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment