title: When testing TypeScript code, can we trust the declared types of parameters or should we test as if we're testing JavaScript code?
body: <p>I'm trying to test a method I've written in TypeScript. Let's say the method signature is as below:</p>
  <pre><code>doTask(value: number): void
  </code></pre>
  <p>Each method parameter is labeled with a type, but I'm worried that the caller will accidentally pass an argument of the wrong type into the method, as such:</p>
  <pre><code>let wrongValue: any = '3';
  doTask(wrongValue);
  </code></pre>
  <p>Therefore, in my tests I want to try passing in arguments of the wrong type and checking to make sure my method doesn't fail silently. However, this requires a lot of extra testing for each parameter in the method and I'd have to do this for each method. It would be like testing JavaScript code.</p>
  <p>I know I could strengthen my specification for this method and tell the caller that this method can ONLY be called with a number, but I don't want to put that much responsibility on the caller. I know I can also use type guards within my method, but I don't want to test based on the implementation.</p>
  <p>I'm new to TypeScript and I'm wondering if there's some accepted practice in this situation? Thanks so much!</p>