From 1ab10adbdcda1c6c0d7c15e932a7f89ce14cbcb8 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 17 Sep 2015 00:53:17 -0700 Subject: [PATCH] Added tests. --- ...TypedClassExpressionMethodDeclaration01.ts | 47 +++++++++++++++++ ...TypedClassExpressionMethodDeclaration02.ts | 51 +++++++++++++++++++ ...lyTypedObjectLiteralMethodDeclaration01.ts | 47 +++++++++++++++++ 3 files changed, 145 insertions(+) create mode 100644 tests/cases/conformance/types/contextualTypes/methodDeclarations/contextuallyTypedClassExpressionMethodDeclaration01.ts create mode 100644 tests/cases/conformance/types/contextualTypes/methodDeclarations/contextuallyTypedClassExpressionMethodDeclaration02.ts create mode 100644 tests/cases/conformance/types/contextualTypes/methodDeclarations/contextuallyTypedObjectLiteralMethodDeclaration01.ts diff --git a/tests/cases/conformance/types/contextualTypes/methodDeclarations/contextuallyTypedClassExpressionMethodDeclaration01.ts b/tests/cases/conformance/types/contextualTypes/methodDeclarations/contextuallyTypedClassExpressionMethodDeclaration01.ts new file mode 100644 index 0000000000..7ceb5bd34b --- /dev/null +++ b/tests/cases/conformance/types/contextualTypes/methodDeclarations/contextuallyTypedClassExpressionMethodDeclaration01.ts @@ -0,0 +1,47 @@ +// @noImplicitAny: true + +interface A { + numProp: number; +} + +interface B { + strProp: string; +} + +interface Foo { + method1(arg: A): void; + method2(arg: B): void; +} + +function getFoo1(): Foo { + return class { + static method1(arg) { + arg.numProp = 10; + } + static method2(arg) { + arg.strProp = "hello"; + } + } +} + +function getFoo2(): Foo { + return class { + static method1 = (arg) => { + arg.numProp = 10; + } + static method2 = (arg) => { + arg.strProp = "hello"; + } + } +} + +function getFoo3(): Foo { + return class { + static method1 = function (arg) { + arg.numProp = 10; + } + static method2 = function (arg) { + arg.strProp = "hello"; + } + } +} \ No newline at end of file diff --git a/tests/cases/conformance/types/contextualTypes/methodDeclarations/contextuallyTypedClassExpressionMethodDeclaration02.ts b/tests/cases/conformance/types/contextualTypes/methodDeclarations/contextuallyTypedClassExpressionMethodDeclaration02.ts new file mode 100644 index 0000000000..2f1f6f079c --- /dev/null +++ b/tests/cases/conformance/types/contextualTypes/methodDeclarations/contextuallyTypedClassExpressionMethodDeclaration02.ts @@ -0,0 +1,51 @@ +// @noImplicitAny: true + +interface A { + numProp: number; +} + +interface B { + strProp: string; +} + +interface Foo { + new (): Bar; +} + +interface Bar { + method1(arg: A): void; + method2(arg: B): void; +} + +function getFoo1(): Foo { + return class { + method1(arg) { + arg.numProp = 10; + } + method2(arg) { + arg.strProp = "hello"; + } + } +} + +function getFoo2(): Foo { + return class { + method1 = (arg) => { + arg.numProp = 10; + } + method2 = (arg) => { + arg.strProp = "hello"; + } + } +} + +function getFoo3(): Foo { + return class { + method1 = function (arg) { + arg.numProp = 10; + } + method2 = function (arg) { + arg.strProp = "hello"; + } + } +} \ No newline at end of file diff --git a/tests/cases/conformance/types/contextualTypes/methodDeclarations/contextuallyTypedObjectLiteralMethodDeclaration01.ts b/tests/cases/conformance/types/contextualTypes/methodDeclarations/contextuallyTypedObjectLiteralMethodDeclaration01.ts new file mode 100644 index 0000000000..ed8912317f --- /dev/null +++ b/tests/cases/conformance/types/contextualTypes/methodDeclarations/contextuallyTypedObjectLiteralMethodDeclaration01.ts @@ -0,0 +1,47 @@ +// @noImplicitAny: true + +interface A { + numProp: number; +} + +interface B { + strProp: string; +} + +interface Foo { + method1(arg: A): void; + method2(arg: B): void; +} + +function getFoo1(): Foo { + return { + method1(arg) { + arg.numProp = 10; + }, + method2(arg) { + arg.strProp = "hello"; + } + } +} + +function getFoo2(): Foo { + return { + method1: (arg) => { + arg.numProp = 10; + }, + method2: (arg) => { + arg.strProp = "hello"; + } + } +} + +function getFoo3(): Foo { + return { + method1: function (arg) { + arg.numProp = 10; + }, + method2: function (arg) { + arg.strProp = "hello"; + } + } +} \ No newline at end of file