Files
test-repo/tests/flow/refinements/switch.js
T
Christopher Chedeau 3375cfe605 Move tests around (#454)
* new_tests

* move_all_clobbered_tests

* remove all the tests that no longer exist

* re-run flow tests

* Move all the flow tests to tests/flow and prettier to tests/

* Move prettier tests to their own folders

* Add jsfmt files

* run prettier snapshot tests
2017-01-24 14:35:37 -08:00

56 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* @flow */
function foo(text: string | number): string {
switch (typeof text) {
  case 'string':
   return text;
case 'number':
return text; // error, should return string
  default:
   return 'wat';
 }
}
function bar(text: string | number): string {
switch (typeof text) {
case 'string':
return text[0];
 default:
return (text++) + '';
 }
}
function baz1(text: string | number): string {
switch (typeof text) {
case 'number':
case 'string':
return text[0]; // error, [0] on number
 default:
return 'wat';
 }
}
function baz2(text: string | number): string {
switch (typeof text) {
case 'string':
case 'number':
return text[0]; // error, [0] on number
 default:
return 'wat';
 }
}
function corge(text: string | number | Array<string>): string {
switch (typeof text) {
case 'object':
return text[0];
case 'string':
case 'number':
// using ++ since it isn't valid on arrays or strings.
// should only error for string since Array was filtered out.
return (text++) + '';
 default:
return 'wat';
 }
}