[K/JS] Add @ts-ignore for the case when there is a class with a private primary constructor (or excluded from export) which has an exported subclass ^Fixed KT-52563
This commit is contained in:
+25
@@ -0,0 +1,25 @@
|
||||
declare namespace JS_TESTS {
|
||||
type Nullable<T> = T | null | undefined
|
||||
namespace foo {
|
||||
class ClassWithoutPrimary {
|
||||
private constructor();
|
||||
get value(): string;
|
||||
static fromInt(value: number): foo.ClassWithoutPrimary;
|
||||
static fromString(value: string): foo.ClassWithoutPrimary;
|
||||
}
|
||||
/* @ts-ignore: extends class with private primary constructor */
|
||||
class SomeBaseClass extends foo.ClassWithoutPrimary {
|
||||
private constructor();
|
||||
get answer(): number;
|
||||
static secondary(): foo.SomeBaseClass;
|
||||
}
|
||||
/* @ts-ignore: extends class with private primary constructor */
|
||||
class SomeExtendingClass extends /* foo.IntermediateClass1 */ foo.SomeBaseClass {
|
||||
private constructor();
|
||||
}
|
||||
/* @ts-ignore: extends class with private primary constructor */
|
||||
class FinalClassInChain extends /* foo.IntermediateClass2 */ foo.SomeExtendingClass {
|
||||
constructor();
|
||||
}
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// KT-52563
|
||||
// CHECK_TYPESCRIPT_DECLARATIONS
|
||||
// RUN_PLAIN_BOX_FUNCTION
|
||||
// SKIP_MINIFICATION
|
||||
// SKIP_NODE_JS
|
||||
// INFER_MAIN_MODULE
|
||||
// MODULE: JS_TESTS
|
||||
// FILE: enum-classes.kt
|
||||
|
||||
package foo
|
||||
|
||||
@JsExport
|
||||
open class ClassWithoutPrimary {
|
||||
val value: String
|
||||
|
||||
@JsName("fromInt")
|
||||
constructor(value: Int) {
|
||||
this.value = value.toString()
|
||||
}
|
||||
|
||||
@JsName("fromString")
|
||||
constructor(value: String) {
|
||||
this.value = value
|
||||
}
|
||||
}
|
||||
|
||||
@JsExport
|
||||
open class SomeBaseClass private constructor(val answer: Int): ClassWithoutPrimary(answer) {
|
||||
@JsName("secondary")
|
||||
constructor() : this(42)
|
||||
}
|
||||
|
||||
open class IntermediateClass1: SomeBaseClass()
|
||||
|
||||
@JsExport
|
||||
open class SomeExtendingClass @JsExport.Ignore public constructor() : IntermediateClass1()
|
||||
|
||||
open class IntermediateClass2: SomeExtendingClass()
|
||||
|
||||
@JsExport
|
||||
class FinalClassInChain: IntermediateClass2()
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
var SomeBaseClass = JS_TESTS.foo.SomeBaseClass;
|
||||
var SomeExtendingClass = JS_TESTS.foo.SomeExtendingClass;
|
||||
var FinalClassInChain = JS_TESTS.foo.FinalClassInChain;
|
||||
function assert(condition) {
|
||||
if (!condition) {
|
||||
throw "Assertion failed";
|
||||
}
|
||||
}
|
||||
function box() {
|
||||
// @ts-expect-error "the constructor is private and can't be used from JS/TS code"
|
||||
var baseClass = new SomeBaseClass(4);
|
||||
assert(baseClass.answer === 4);
|
||||
// @ts-expect-error "the constructor is private and can't be used from JS/TS code"
|
||||
var extendingClass = new SomeExtendingClass();
|
||||
assert(extendingClass.answer === 42);
|
||||
var finalClassInChain = new FinalClassInChain();
|
||||
assert(finalClassInChain.answer === 42);
|
||||
return "OK";
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
import SomeBaseClass = JS_TESTS.foo.SomeBaseClass;
|
||||
import SomeExtendingClass = JS_TESTS.foo.SomeExtendingClass;
|
||||
import FinalClassInChain = JS_TESTS.foo.FinalClassInChain;
|
||||
|
||||
function assert(condition: boolean) {
|
||||
if (!condition) {
|
||||
throw "Assertion failed";
|
||||
}
|
||||
}
|
||||
|
||||
function box(): string {
|
||||
// @ts-expect-error "the constructor is private and can't be used from JS/TS code"
|
||||
const baseClass = new SomeBaseClass(4)
|
||||
assert(baseClass.answer === 4)
|
||||
|
||||
// @ts-expect-error "the constructor is private and can't be used from JS/TS code"
|
||||
const extendingClass = new SomeExtendingClass()
|
||||
assert(extendingClass.answer === 42)
|
||||
|
||||
const finalClassInChain = new FinalClassInChain()
|
||||
assert(finalClassInChain.answer === 42)
|
||||
|
||||
return "OK";
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"include": [ "./*" ],
|
||||
"extends": "../common.tsconfig.json"
|
||||
}
|
||||
Reference in New Issue
Block a user