Skip to content

Instantly share code, notes, and snippets.

npm install --save-dev @types/jasmine
declare function camelize(s: string): string;
let user = { firstName: "James", lastName: "Hetfield" };
console.log(greeter(user));
interface Person {
firstName: string;
lastName: string;
}
function greeter(person: Person): string {
return "Hello, " + person.firstName + " " + person.lastName;
}
// Jasmine spec:
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() {
function greeter(person) {
return "Hello, " + person.firstName + " " + person.lastName;
}
class Greeter {
greeting: string;
constructor(message: string) {
this.greeting = message;
}
greet() {
return "Hello, " + this.greeting;
}
class Greeter {
constructor(message) {
this.greeting = message;
}
greet() {
return "Hello, " + this.greeting;
}
}
@dpashkevich
dpashkevich / camelize.d.ts
Created November 19, 2018 04:39
Gists for article "7 outdated excuses to avoid TypeScript"
declare function camelize(s: string): string;
- Trailing commas are ok
- No reserved words for property names
- NaN, Infinity, undefined : are all constants
- parseInt() defaults to radix 10
- /regexp/ produces new reg ex object every time
- JSON.parse(), JSON.stringify()
- Function.prototype.bind
- String.prototype.trim
- Array.prototype.every, filter, forEach, indexOf, lastIndexOf, map, reduce, reduceRight, some,
- Date.now()