News for hackers. Stuff that matters.
Re:JavaScript for People Who Hate JavaScript by styfle on Wednesday August 09, 2017 @01:40PM (#14971669)
Yes, a runtime check in TypeScript is the same as a runtime check in JavaScript.

    function inc(n) {
      if (typeof n === 'number') { return n + 1 }
      throw new Error('Parameter n is not a number');
    }
If you wanted to actually runtime check all types (probably not advised) you could parse the type annotations.

Or you could define your types using something like JSON Schema and validate against that.

https://github.com/bcherny/json-schema-to-typescript

https://github.com/YousefED/typescript-json-schema

Re:JavaScript for People Who Hate JavaScript by slackingoff2017 on Wednesday August 09, 2017 @06:54PM (#14974523)
I'm sorry to say but... This check won't help with accidental incorrect casts. Typeof in typescript is a pass through for the JavaScript function, so it only returns what the JS version does.

A check for a string or number will work, but a check against a typescript object or something complex like a union type will just return 'Object'

Re:JavaScript for People Who Hate JavaScript by spion on Saturday August 19, 2017 @11:23AM (#15053885)
You can use a tslint rule to block casts. That way you will only be able to use type guards to change the type of something.