Edoardo Luppi
08/11/2023, 9:39 AM__doNotUseOrImplementIt
field in the generated d.ts files?
export declare namespace com.my.pkg {
interface MyType {
toString(): string;
readonly __doNotUseOrImplementIt: {
readonly "com.my.pkg.MyType": unique symbol;
};
}
}
Artem Kobzar
08/11/2023, 9:47 AMEdoardo Luppi
08/11/2023, 9:50 AMArtem Kobzar
08/11/2023, 9:55 AMclass Admin {
constructor(public readonly email: string) {}
}
class RegularUser {
constructor(public readonly email: string) {}
}
Their instances are identical for the type checker: https://www.typescriptlang.org/play?ssl=6&ssc=2&pln=1&pc=1#code/MYGwhgzhAECCAmBbAlgO2gbwFDV9YA9qhAC4BO[…]A2IAkQuPaRD47FT88ulAHpf6AAOQA8tAAKJaLTArRAA
The same is for interfaces, but in Kotlin all the interfaces are nominal, so they are not equal even if they have the same structure: https://pl.kotl.in/U1gmb9McAArtem Kobzar
08/11/2023, 9:58 AMimplements
keyword in TS to implement an interface because interfaces in TS are not runtime entities, so, you can't have default implementations and make a runtime type check for the interface: https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgGIHt3IN4ChkHID0RyMmAFAJQBcyAzm[…]HR66CwUIBAA7iboFtbUyKCMcCBI6DBRVMSkMvE+lhAIYMDeqlDqUEA
So, if we will allow to use implements
from TS, it will break all the runtime type checks for the interface and their implementations will lose all the default implementations.Edoardo Luppi
08/11/2023, 10:01 AMJsExport
-ing interfaces, we can't really use them from the TS side.Artem Kobzar
08/11/2023, 10:04 AMEdoardo Luppi
08/11/2023, 10:05 AMEdoardo Luppi
08/11/2023, 10:09 AMEdoardo Luppi
08/11/2023, 11:05 AMArtem Kobzar
08/11/2023, 11:29 AMEdoardo Luppi
08/11/2023, 11:39 AMEdoardo Luppi
08/11/2023, 2:07 PM