You can declare a `dynamic` Kotlin variable like this:
val myObject: dynamic = null
The myObject above is not type-safe. It seems that the reason for its existence is interop with existing JavaScript code.The Kotlin `Any` class is actaully more related to Java's `Object` class. (It's the superclass of every Kotlin class.)
function inc(n) {
if (typeof n === 'number') { return n + 1 }
throw new Error('Parameter n is not a number');
}
If you wanted to actually runtime check all types (probably not advised) you could parse the type annotations.Or you could define your types using something like JSON Schema and validate against that.
A check for a string or number will work, but a check against a typescript object or something complex like a union type will just return 'Object'
Note that Typescript tries to follow JS to remain a superset that easily compiles down, and the metadata API is currently a stage II Ecma proposal so it's marked experimental.
It should be fairly easy to build a types casting method using that.
If you want top-type like behavior in TS, you want to use `{}` instead of any, since the language is structural. Anything satisfies it, but it exposes no members without a cast or guard to a more specific type.
Kotlin's Any is pretty much the opposite of TypeScript's any. In TS it disables type checking completely (according to the docs). In Kotlin it's the top type (similar to Java's Object type), which anything conforms with, but doesn't expose any operations at all (except for the stuff that the JVM provides for free).
The closest match to TS' any would probably be C#'s dynamic https://docs.microsoft.com/en-us/dotnet/csharp/programming-g....