Skip to content

Instantly share code, notes, and snippets.

@groteck
Last active July 5, 2021 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save groteck/b2b0eaf1126b6197ac2469fffd5f12dc to your computer and use it in GitHub Desktop.
Save groteck/b2b0eaf1126b6197ac2469fffd5f12dc to your computer and use it in GitHub Desktop.
Examples of Typescript
// ?. Mixed with the type system
let thing: number | undefined | string | { descripcion: string } = 1;
console.log(thing?.descripcion); // => test.ts(2,20): error TS2339: Property 'descripcion' does not exist on type 'number'.
thing = "test";
console.log(thing?.descripcion); // => test.ts(5,20): error TS2339: Property 'descripcion' does not exist on type 'string'.
thing = { descripcion: "test" };
console.log(thing?.descripcion); //=> test.ts(11,20): error TS2339: Property 'descripcion' does not exist on type 'string | number | { descripcion: string; }'.
thing = undefined;
console.log(thing?.descripcion); // => undefined
// const in ts and js
const constTest: { prop1: string } = { prop1: "test" };
console.log(constTest.prop1); //=> test
constTest.prop1 = "replaced";
console.log(constTest.prop1); //=> replaced
constTest = { ...constTest }; //=> test.ts(8,1): error TS2588: Cannot assign to 'constTest' because it is a constant.
console.log(constTest.prop1);
// Fetch query
const [
loadCarsByVIN, // -> Call that you need to trigger to pull data `loadCarsByVIN({variables: {vin: "exampleVin"}})`;
// true/false error message on fail function mock server response query result. pull data ignores cache
// | | | | |
{ loading, error, updateQuery, data, refetch, called },
] = useLazyQuery<CarByVINData, CarByVINVars>(CarByVIN);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment