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 getUserById(id: any){ | |
// hits a database and returns the value | |
} | |
const guid = "b5f770f2-197c-4bf5-a31f-cfec4f545d06"; | |
const user = getUserById(guid); | |
// ^^^ Runtime Error: PL/SQL: ORA-00932: inconsistent datatypes: expected NUMBER got - TEXT |
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 getUserById(id: any){ | |
// hits a database and returns the value | |
} | |
const guid = "b5f770f2-197c-4bf5-a31f-cfec4f545d06"; | |
const user = getUserById(guid); | |
// ^^^ Runtime Error: PL/SQL: ORA-00932: inconsistent datatypes: expected NUMBER got - TEXT |
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 getUserById(id: number){ | |
// hits a database and returns the value | |
} | |
const guid = "b5f770f2-197c-4bf5-a31f-cfec4f545d06"; | |
const user = getUserById(guid); | |
// ^ Compiler error: Argument of type string is not assignable to parameter of type 'number'. |
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 martyrAlgorithm(newUserToSave){ | |
if(!newUserToSave.lastName){ | |
throw new Error("I did my best, but I can't save this new user since you didn't get me a lastName") | |
} | |
globals.databaseHandle.save(newUserToSave); | |
} |
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 { IUserDbInstance, UserDB } from 'UserDatabase'; | |
interface INewUser { | |
firstName: string, | |
middleName?: string, | |
lastName: string | |
} | |
function honestDbMethod(newUserToSave: INewUser, dbInstance: IUserDbInstance){ | |
// if(newUserToSave.lastName){ // This if statement is unnecessary because you asked for what you need |
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
type ITrafficLight = "red" | |
| "redBlinking" // <-- new case | |
| "green" | |
| "yellow" | |
| "yellowBlinking"; // <-- new case | |
// Can you spot the bug? | |
// You can skip ahead to the answer here: https://gist.github.com/TheCubicleBuddha/7a8854f244697b9894e41d44e1fc6967 | |
function respondToTrafficSignal(signal: ITrafficLight): "stop" | "go" | "pause" { |
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
type ITrafficLight = "red" | "green" | "yellow"; | |
// Can you see where the function below might go wrong in the future? | |
// You can skip ahead to the answer here: https://gist.github.com/TheCubicleBuddha/7a8854f244697b9894e41d44e1fc6967 | |
function respondToTrafficSignal(signal: ITrafficLight): "stop" | "go" | "pause" { | |
if(signal === "red"){ | |
return "stop"; | |
} else if(signal === "yellow"){ | |
return "pause"; |
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
type ITrafficLight = "red" | "redBlinking" | "green" | "yellow" | "yellowBlinking"; | |
function respondToTrafficSignal(signal: ITrafficLight): "stop" | "go" | "pause" { | |
if(signal === "red"){ | |
return "stop"; | |
} else if(signal === "yellow"){ | |
return "pause"; | |
} else if(signal === "green") { | |
return "go"; | |
} else { |