diff --git a/tests/baselines/reference/declFileTypeAnnotationStringLiteral.js b/tests/baselines/reference/declFileTypeAnnotationStringLiteral.js new file mode 100644 index 0000000000..faa76cc869 --- /dev/null +++ b/tests/baselines/reference/declFileTypeAnnotationStringLiteral.js @@ -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; diff --git a/tests/baselines/reference/declFileTypeAnnotationStringLiteral.types b/tests/baselines/reference/declFileTypeAnnotationStringLiteral.types new file mode 100644 index 0000000000..d50d95f988 --- /dev/null +++ b/tests/baselines/reference/declFileTypeAnnotationStringLiteral.types @@ -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 +} diff --git a/tests/cases/compiler/declFileTypeAnnotationStringLiteral.ts b/tests/cases/compiler/declFileTypeAnnotationStringLiteral.ts new file mode 100644 index 0000000000..0cdd27fd62 --- /dev/null +++ b/tests/cases/compiler/declFileTypeAnnotationStringLiteral.ts @@ -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; +} \ No newline at end of file