Test case for string literal overload type annotation
This commit is contained in:
parent
c2188a329d
commit
9e41b0fed4
|
@ -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;
|
|
@ -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
|
||||||
|
}
|
13
tests/cases/compiler/declFileTypeAnnotationStringLiteral.ts
Normal file
13
tests/cases/compiler/declFileTypeAnnotationStringLiteral.ts
Normal 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;
|
||||||
|
}
|
Loading…
Reference in a new issue