K..
K..

Reputation: 4233

How do JavaScript unit-tests differ from their TypeScript equivalent?

I'm used to dynamic languages, but TypeScripts structural typing sounds like an almost dynamic addition to JavaScript.

Now I read, TypeScript would eliminate many unit-tests a JavaScript program needs.

What kind of unit-tests are essential for TypeScript 2.0?

What errors can't the type checker get?

(I'm asking for TS2, because I guess the new additions of flow-analysis and non-nullable-types eliminate their own kind of tests)

Upvotes: 0

Views: 46

Answers (2)

Ray
Ray

Reputation: 3109

What kind of unit-tests are essential for TypeScript 2.0?

Ask yourself,

What kind of unit-tests are essential for Javascript?

There are an infinite number of errors that Typescript can't catch. TypeScript will eliminate a lot of errors that dynamic languages can't, so that leaves (infinity - some = infinity) errors left for you to check. Good Luck! :}

Upvotes: 1

basarat
basarat

Reputation: 276393

What errors can't the type checker get

The ones that aren't expressed in the type system. e.g. the length of a character isn't expressed:

let x: string; 
x = theValueThatWasReceivedFromServer;
// read the 10th character 
// As far as ts is concerned it is okay. 
// It might be undefined based on the value that came from the server
console.log(x[10]);

Upvotes: 1

Related Questions