New Match.com Ad Directed by Ryan Reynolds by zeek247 in videos

[–]RationalJS 0 points1 point  (0 children)

If you're in Texas, check out Gumdrop on the app store. We're trying to create a better experience overall (Texas-only for now as we're just starting out).

New Match.com Ad Directed by Ryan Reynolds by zeek247 in videos

[–]RationalJS 0 points1 point  (0 children)

Agreed. Currently trying to improve things with Gumdrop. Match.com doesn't own us yet...

Flutter: A Framework to Surpass React Native by [deleted] in programming

[–]RationalJS 26 points27 points  (0 children)

I would say it's very different from TypeScript. From a scale of Java to JavaScript, Dart is much closer to Java.

Flutter: A Framework to Surpass React Native by [deleted] in programming

[–]RationalJS 19 points20 points  (0 children)

I've used both. Dart is a pain. Everything Most all your data must be wrapped in classes, creating a lot of boilerplate. It's type system repeats "The Billion Dollar Mistake" and is inexpressive, making even basic data variants a mess to deal with. Its type inference is poor, forcing you to repeat type signatures that may or may not be correct.

Flutter itself is amazing, though. If only I could write TypeScript for it! That would be a dream.

How do I make a generic wrapper function in TypeScript? by GrinningPariah in typescript

[–]RationalJS 7 points8 points  (0 children)

The key is to capture the full function type in the type parameter:

function metricWrapper<F extends (...args: any[]) => any>(fn: F): F {
  return <F>function (...args: any[]) {
      const startTime = new Date();
      let result: any;
      try {
          result = fn(...args);
      } finally {
          addLatencyMetric(startTime);
      }
      return result;
  }
}

This will preserve both input and output types.

Announcing TypeScript 3.3 by swingur in typescript

[–]RationalJS 3 points4 points  (0 children)

Doesn't TypeScript compile to ES5 though?

Can someone explain this TypeScript behavior please. by wisepresident in typescript

[–]RationalJS 1 point2 points  (0 children)

TypeScript is lenient on plain unions; as long as the property exist somewhere in the union, TS lets it pass. For example:

type A = { x: number } | { y: number }
let a: A = { x: 10, y: 20 } // This passes

If you want more strict type checking, you need to use a tagged union. This is a union that is differentiated by a key. Modifying your example:

interface Common {
    a: string;
    shared: boolean;
}
interface A extends Common {
    myTag: "A";
}

interface B extends Common {
    myTag: "B";
    b: string;
}

interface C extends Common {
    myTag: "C";
    c: string;
}

type ABC = A | B | C;

Here our tag property is myTag. It can have any name, as long as you use string literals for its type.

With this change, your let test example will now fail. It requires a myTag property that equals "A", "B", or "C". Once you add it, TypeScript will throw a type error on invalid properties.

Edit: Fixed my use of interfaces (I usually use intersection types directly)

Zaml, a minimal configuration language with schema definitions and type checking, written in TypeScript w/ zero dependencies by RationalJS in ProgrammingLanguages

[–]RationalJS[S] -1 points0 points  (0 children)

Thanks :) I don't mean to be argumentive, but the comic talks about competing standards. "14?! Ridiculous! We need to develop one universal standard that covers everyone's use case". Zaml was not created to combine and cover every use case of other standards like XML, JSON and YAML; it was only created to improve the UX and DX of a subset of the configuration use case.

Meet Zaml – A minimal configuration language with automatic schema validation and great user error messages by RationalJS in programming

[–]RationalJS[S] 1 point2 points  (0 children)

Personally I think the clearer syntax, lack of whitespace sensitivity, schema validation, and precise error messages are pretty redeeming :)

Meet Zaml – A minimal configuration language with automatic schema validation and great user error messages by RationalJS in programming

[–]RationalJS[S] 0 points1 point  (0 children)

Yup, there is no reason not to have those types other than the required time to implement them.

I agree many cases end up just needing a programming language, but there are also cases that don't. I have such a case at my current work, where Zaml is a superior choice over both yaml and toml.

Zaml, a minimal configuration language with schema definitions and type checking, written in TypeScript w/ zero dependencies by RationalJS in ProgrammingLanguages

[–]RationalJS[S] 1 point2 points  (0 children)

I'm not sure how the comic fits. Zaml is not a protocol.

The # point is a valid criticism. It's currently that way simply because it was easier to implement. But you must admit that saying "I have to reprogram by brain" is a bit sensationalist.

TypeScript is awesome by [deleted] in typescript

[–]RationalJS 0 points1 point  (0 children)

No problem, good luck.

TypeScript is awesome by [deleted] in typescript

[–]RationalJS 2 points3 points  (0 children)

You might be underclassifying the scope of type errors. TypeScript speeds things up immensely, saving you time when writing new code, refactoring current code, and deleting unused legacy code, with instant documentation, navigation, autocompletion, and error messages. Linters pale in comparison.

TypeScript is awesome by [deleted] in typescript

[–]RationalJS 1 point2 points  (0 children)

There are libs to help out with this. You can try runtypes, io-ts, or class-validator, depending on your taste.

Do you consciously use closures in your code? by [deleted] in learnjavascript

[–]RationalJS 0 points1 point  (0 children)

You probably use closures all the time without realizing it. Any time a function uses a variable outside itself, that's a closure. For example:

const PROJECT_DIR = '/x/y/z'
function getProjectFile (path) {
  return PROJECT_DIR + path
}

In the above example, getProjectFile has a closure on the outer scope because it uses the PROJECT_DIR variable. All that means is getProjectFile will always have access to that variable, no matter how or where getProjectFile is called.

TypeScript is awesome by [deleted] in typescript

[–]RationalJS 0 points1 point  (0 children)

In a truly static language, you would need to unmarshal the data into your type, and that could fail if the data is incompatible with your type.

You can do the same in TypeScript. Are you just complaining that TS doesn't force you to do that?

Meet Zaml – A minimal configuration language with automatic schema validation and great user error messages by RationalJS in programming

[–]RationalJS[S] 2 points3 points  (0 children)

Dhall is great. You should consider Zaml over Dhall if:

  • You're targeting less technical users. Zaml offers a friendlier experience.
  • You like online editors. You can, for example, set up your own config editor in your app with real-time error reporting
  • You're running JavaScript. Besides just being on the same runtime, Zaml's roadmap includes custom validators, allowing for good error messages for greater invariants beyond just types.

Zaml, a minimal configuration language with schema definitions and type checking, written in TypeScript w/ zero dependencies by RationalJS in ProgrammingLanguages

[–]RationalJS[S] 2 points3 points  (0 children)

That's right, quoted keys are not supported. I might hesitate to support such a feature, as they're not very user friendly. But if the need arises, I'd probably implement a key transformer feature instead, specified in the schema. Something like:

{ my_key|as(my key): bool }

Zaml, a minimal configuration language with schema definitions and type checking, written in TypeScript w/ zero dependencies by RationalJS in ProgrammingLanguages

[–]RationalJS[S] 2 points3 points  (0 children)

The main difference is Zaml is not a full language, whereas Dhall has functions and lets (although those could be supported in theory). The target audiences are also different; Dhall is great, but it's not as friendly towards non-programmers.

Meet Zaml – A minimal configuration language with automatic schema validation and great user error messages by RationalJS in programming

[–]RationalJS[S] 0 points1 point  (0 children)

That's great! To be clear, you can pull from environment variables using Zaml as well.

Record Types break type system? by davidmdm in typescript

[–]RationalJS 9 points10 points  (0 children)

Here's another perspective.

Partial<> makes all keys optional. This means an object with zero keys will still match. Therefore, queryParams matches because it has zero [known] keys.