From a6d1f30e89759c14d0581a8c5c84e276c2594132 Mon Sep 17 00:00:00 2001 From: Artem Kobzar Date: Wed, 7 Sep 2022 12:46:45 +0000 Subject: [PATCH] chore: generate extra files. --- .../interfaces-in-exported-file/interfaces.d.ts | 7 +++++++ .../interfaces-in-exported-file/interfaces.kt | 11 +++++++++++ .../interfaces-in-exported-file/interfaces__main.js | 4 ++++ .../interfaces-in-exported-file/interfaces__main.ts | 5 +++++ 4 files changed, 27 insertions(+) diff --git a/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces.d.ts b/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces.d.ts index 06fd2f146aa..7a8cadd01cc 100644 --- a/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces.d.ts +++ b/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces.d.ts @@ -1,5 +1,11 @@ declare namespace JS_TESTS { type Nullable = T | null | undefined + namespace foo { + interface OptionalFieldsInterface { + readonly required: number; + readonly notRequired?: Nullable; + } + } namespace foo { interface TestInterface { readonly value: string; @@ -24,5 +30,6 @@ declare namespace JS_TESTS { readonly __doNotUseOrImplementIt: foo.TestInterfaceImpl["__doNotUseOrImplementIt"] & foo.AnotherExportedInterface["__doNotUseOrImplementIt"]; } function processInterface(test: foo.TestInterface): string; + function processOptionalInterface(a: foo.OptionalFieldsInterface): string; } } \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces.kt b/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces.kt index d60a07badf8..0697bba8fea 100644 --- a/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces.kt +++ b/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces.kt @@ -34,4 +34,15 @@ class ChildTestInterfaceImpl(): TestInterfaceImpl("Test"), AnotherExportedInterf fun processInterface(test: TestInterface): String { return "Owner ${test.getOwnerName()} has value '${test.value}'" +} + + +external interface OptionalFieldsInterface { + val required: Int + val notRequired: Int? +} + + +fun processOptionalInterface(a: OptionalFieldsInterface): String { + return "${a.required}${a.notRequired ?: "unknown"}" } \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces__main.js b/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces__main.js index f3aba8a8c27..72a187b6c99 100644 --- a/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces__main.js +++ b/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces__main.js @@ -2,6 +2,7 @@ var TestInterfaceImpl = JS_TESTS.foo.TestInterfaceImpl; var ChildTestInterfaceImpl = JS_TESTS.foo.ChildTestInterfaceImpl; var processInterface = JS_TESTS.foo.processInterface; +var processOptionalInterface = JS_TESTS.foo.processOptionalInterface; function assert(condition) { if (!condition) { throw "Assertion failed"; @@ -12,5 +13,8 @@ function box() { assert(processInterface(new ChildTestInterfaceImpl()) === "Owner TestInterfaceImpl has value 'Test'"); // @ts-expect-error "Just test that this code will throw compilation error for a user" assert(processInterface({ value: "bar", getOwnerName: function () { return "RandomObject"; } }) === "Owner RandomObject has value 'bar'"); + assert(processOptionalInterface({ required: 4 }) == "4unknown"); + assert(processOptionalInterface({ required: 4, notRequired: null }) == "4unknown"); + assert(processOptionalInterface({ required: 4, notRequired: 5 }) == "45"); return "OK"; } diff --git a/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces__main.ts b/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces__main.ts index c16a4278309..de5842b2b27 100644 --- a/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces__main.ts +++ b/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces__main.ts @@ -1,6 +1,7 @@ import TestInterfaceImpl = JS_TESTS.foo.TestInterfaceImpl; import ChildTestInterfaceImpl = JS_TESTS.foo.ChildTestInterfaceImpl; import processInterface = JS_TESTS.foo.processInterface; +import processOptionalInterface = JS_TESTS.foo.processOptionalInterface; function assert(condition: boolean) { if (!condition) { @@ -15,5 +16,9 @@ function box(): string { // @ts-expect-error "Just test that this code will throw compilation error for a user" assert(processInterface({ value: "bar", getOwnerName: () => "RandomObject" }) === "Owner RandomObject has value 'bar'") + assert(processOptionalInterface({ required: 4 }) == "4unknown") + assert(processOptionalInterface({ required: 4, notRequired: null }) == "4unknown") + assert(processOptionalInterface({ required: 4, notRequired: 5 }) == "45") + return "OK"; } \ No newline at end of file