Test case for string literal overload type annotation

This commit is contained in:
Sheetal Nandi 2014-11-10 17:09:34 -08:00
parent c2188a329d
commit 9e41b0fed4
3 changed files with 70 additions and 0 deletions

View file

@ -0,0 +1,26 @@
//// [declFileTypeAnnotationStringLiteral.ts]
function foo(a: "hello"): number;
function foo(a: "name"): string;
function foo(a: string): string | number;
function foo(a: string): string | number {
if (a === "hello") {
return a.length;
}
return a;
}
//// [declFileTypeAnnotationStringLiteral.js]
function foo(a) {
if (a === "hello") {
return a.length;
}
return a;
}
//// [declFileTypeAnnotationStringLiteral.d.ts]
declare function foo(a: "hello"): number;
declare function foo(a: "name"): string;
declare function foo(a: string): string | number;

View file

@ -0,0 +1,31 @@
=== tests/cases/compiler/declFileTypeAnnotationStringLiteral.ts ===
function foo(a: "hello"): number;
>foo : { (a: "hello"): number; (a: "name"): string; (a: string): string | number; }
>a : "hello"
function foo(a: "name"): string;
>foo : { (a: "hello"): number; (a: "name"): string; (a: string): string | number; }
>a : "name"
function foo(a: string): string | number;
>foo : { (a: "hello"): number; (a: "name"): string; (a: string): string | number; }
>a : string
function foo(a: string): string | number {
>foo : { (a: "hello"): number; (a: "name"): string; (a: string): string | number; }
>a : string
if (a === "hello") {
>a === "hello" : boolean
>a : string
return a.length;
>a.length : number
>a : string
>length : number
}
return a;
>a : string
}

View file

@ -0,0 +1,13 @@
// @target: ES5
// @declaration: true
function foo(a: "hello"): number;
function foo(a: "name"): string;
function foo(a: string): string | number;
function foo(a: string): string | number {
if (a === "hello") {
return a.length;
}
return a;
}