notes

Patch broken node_module with yarn22021. 3. 9.

  1. yarn patch <module>
  2. fix the code inside the generated folder and save it.
  3. yarn patch-commit <generated_folder> > <patch_file_name>.diff
  4. fix package.json with "module": "patch:<module>@<version>#<path_to_patch_file>/<patch_file_name>.diff"
  5. yarn install

as const2021. 1. 21.

type predicate2021. 1. 11.

interface Article {
   title: string;
   body: string;
}

function isArticle(body: unknown): body is Article {
  let b = body as Article;
  return !!b && typeof b.body === 'string' && typeof b.title === 'string';
}
interface Article {
   title: string;
   body: string;
}

function isArticle(body: unknown): body is Article {
  let b = body as Article;
  return !!b && typeof b.body === 'string' && typeof b.title === 'string';
}

xcrun: error: active developer path ("/Applications/Xcode.app/Contents/Developer") does not exist2020. 12. 11.

GHCi, version 8.4.3: http://www.haskell.org/ghc/  :? for help
xcrun: error: active developer path ("/Applications/Xcode.app/Contents/Developer") does not exist
Use `sudo xcode-select --switch path/to/Xcode.app` to specify the Xcode that you wish to use for command line developer tools, or use `xcode-select --install` to install the standalone command line developer tools.
See `man xcode-select` for more details.
`clang' failed in phase `gcc'. (Exit code: 1)
GHCi, version 8.4.3: http://www.haskell.org/ghc/  :? for help
xcrun: error: active developer path ("/Applications/Xcode.app/Contents/Developer") does not exist
Use `sudo xcode-select --switch path/to/Xcode.app` to specify the Xcode that you wish to use for command line developer tools, or use `xcode-select --install` to install the standalone command line developer tools.
See `man xcode-select` for more details.
`clang' failed in phase `gcc'. (Exit code: 1)

sudo xcode-select -switch /Library/Developer/CommandLineTools
sudo xcode-select -switch /Library/Developer/CommandLineTools

Beware! Array methods will do shallow copies2020. 11. 19.

const obj1 = { id: 1, name: "obj1" };
const obj2 = { id: 2, name: "obj2" };
const obj3 = { id: 3, name: "obj3" };

const arr = [obj1, obj2, obj3];

const mappedArr = arr.map((obj) => obj);
const filteredArr = arr.filter((obj) => obj.id !== 3);
const reducedArr = arr.reduce((acc, item) => {
  if (item.id === 3) {
    return acc;
  }
  return [...acc, item];
}, []);

const mappedAndSpreadedArr = arr.map((obj) => ({ ...obj }));
const reducedAndSpreadedArr = arr.reduce((acc, item) => {
  if (item.id === 3) {
    return acc;
  }
  return [...acc, { ...item }];
}, []);

console.log(obj1 === mappedArr[0]); // true
console.log(obj1 === mappedAndSpreadedArr[0]); // false

console.log(obj1 === filteredArr[0]); // true

console.log(obj1 === reducedArr[0]); // true
console.log(obj1 === reducedAndSpreadedArr[0]); // false

const findedObj1 = mappedArr.find((obj) => obj.id === 1);
findedObj1.name = "lol";
console.log(obj1.name); // 'lol'

const findedObj2 = mappedAndSpreadedArr.find((obj) => obj.id === 2);
findedObj2.name = "lol";
console.log(obj2.name); // 'obj2'
const obj1 = { id: 1, name: "obj1" };
const obj2 = { id: 2, name: "obj2" };
const obj3 = { id: 3, name: "obj3" };

const arr = [obj1, obj2, obj3];

const mappedArr = arr.map((obj) => obj);
const filteredArr = arr.filter((obj) => obj.id !== 3);
const reducedArr = arr.reduce((acc, item) => {
  if (item.id === 3) {
    return acc;
  }
  return [...acc, item];
}, []);

const mappedAndSpreadedArr = arr.map((obj) => ({ ...obj }));
const reducedAndSpreadedArr = arr.reduce((acc, item) => {
  if (item.id === 3) {
    return acc;
  }
  return [...acc, { ...item }];
}, []);

console.log(obj1 === mappedArr[0]); // true
console.log(obj1 === mappedAndSpreadedArr[0]); // false

console.log(obj1 === filteredArr[0]); // true

console.log(obj1 === reducedArr[0]); // true
console.log(obj1 === reducedAndSpreadedArr[0]); // false

const findedObj1 = mappedArr.find((obj) => obj.id === 1);
findedObj1.name = "lol";
console.log(obj1.name); // 'lol'

const findedObj2 = mappedAndSpreadedArr.find((obj) => obj.id === 2);
findedObj2.name = "lol";
console.log(obj2.name); // 'obj2'

Tags