saguiar's comments

saguiar | 9 years ago | on: Gödel's Incompleteness Theorems (2015)

Agreed it has been abused. On the other hand, if you adhere to a computational theory of mind and see the mind as computation over a formal system, then it is saying something about the mind and the fact that some (true) sentences cannot be proven in that system, isn't it? It is a big if though.

(though maybe in a completely irrelevant sense of truth).

saguiar | 9 years ago | on: If TypeScript is so great, how come all notable ReactJS projects use Babel?

I've been using discriminated unions on TS 2 to do this, and works quite well.

Example:

  const INCREMENT: "increment" = "increment";
  const DECREMENT: "decrement" = "decrement";

  interface Increment {
      type: typeof INCREMENT;
      payload: {
          inc: number;
      };
  }

   interface Decrement {
      type: typeof DECREMENT;
      payload: {
          dec: number;
      };
  }

  interface State { 
      count: number; 
  }

  type Actions = Increment | Decrement;

  function reducer(state: State, action: Actions) {
     switch (action.type) {
        case INCREMENT: {
             const { inc } = action.payload;
             return { count: state.count + inc };
         }
         case DECREMENT: {
             const { dec } = action.payload;
             return { count: state.count + dec };
         }
         default:
             return state;
     }
  }
Once TS figures out the action type is INCREMENT, it can infer the type of the payload. You don't need the Actions type either, you can just receive action: Increment | Decrement.

saguiar | 9 years ago | on: Plottable.js – Flexible, interactive charts for the web

The odd thing is that they are not using three:

    public connectorsEnabled(enabled: boolean): this;
    public connectorsEnabled(): boolean;
    public connectorsEnabled(enabled?: boolean): any {
      if (enabled == null) {
        return this._connectorsEnabled;
      }
      this._connectorsEnabled = enabled;
      return this;
    }
In that way, typescript will use the most specific overload to do type checking, so you'll get an actual boolean when doing connectorsEnabled(); instead of any.
page 1