Skip to content

Instantly share code, notes, and snippets.

View andrevmatos's full-sized avatar

André Vitor de Lima Matos andrevmatos

  • Stealth Company
  • Campinas, SP, BR
  • 17:57 (UTC -03:00)
View GitHub Profile
@andrevmatos
andrevmatos / issue
Created April 21, 2019 19:18
Arch Linux /etc/issue

      ### ### ##
    ## ##
┌ #### ### ###   ####   ## ### ## ### ### ### ### ###  ### ###
│  ##  ### ##  ##   ###  [1;37;
@andrevmatos
andrevmatos / 01_ts2_assert.md
Last active August 12, 2020 02:02
Typescript Tasks

Flexible assert

assert functions and statements are so omnipresent in almost all programming languages in the last couple of decades, it's almost ironic JavaScript/TypeScript not having it built-in. But it's very easy to implement one. Usually, they receive a condition to test as first parameter, and an optional error to throw as second parameter.

We don't want to throw strings (bad practice), so we wanna wrap them with our custom AssertionFailed error class. But we may want to be more descriptive and provide some more details as a second parameter to such class. We don't want to construct these parameters every time an assertion is run, these can be expensive to fetch and would be needed only if the assertion failed. Uff, there's a lot of cases...

Your task is to write an assert function/guard, which can receive the error parameter in multiple ways:

  • an error string, to be fed to our custom class constructor
  • an error instance, to be thrown directly
  • a tuple containing the error message and

Keybase proof

I hereby claim:

  • I am andrevmatos on github.
  • I am andrevmatos (https://keybase.io/andrevmatos) on keybase.
  • I have a public key whose fingerprint is 9A98 76D8 66A1 D4D5 BD12 A24E A48A 6B2D BAC1 EC29

To claim this, I am signing this object: