How do I explicitly declare the type of the variable as object in Haxe?

user9564371

If I have a variable called str that is a String, I can do the following

var str:String = "value";

However, I don't know what kind of type I need to use for a generic object like this

var myObj:???? = {
  key1: value1,
  key2: value2
}

I know I don't need to declare it but I still want to know what the proper text is in place of ????

Type.typeof() says it's a TObject but I can't use that.

Confidant

If you plan on reusing this structure you should look at defining a Class or Typedef. Otherwise, you don't necessarily have to provide a type. You could just do the following and let the compiler assign its own type:

var myObj = {
      key1: "foo",
      key2: "bar"
    };

If using a typedef you would do like:

typedef FooBar = {
  var foo : String;
  var bar : String;
}
var myObj:FooBar = {
  foo: "foo",
  bar: "bar"
};

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I explicitly declare a variable of some Phaser type?

Ocaml - how do I explicitly declare the list mutable type

How do I declare a type variable that extends a Parameterised type?

How do I declare the type of a variable to be the type returned by an observable function?

How can I declare the Type of a Variable in a Julia Object?

How do i declare and define a variable of a custom type in one line

How do I declare a variable with a type from another package in Go?

How do I declare a variable that has a type and implements a protocol?

How do I declare a variable of enum type in Kotlin?

How do I store the type of an object in a variable?

Is it possible to explicitly declare the type of a local variable in PHP?

How to explicitly declare type of a variable when creating that variable with New-Variable function?

Why do I have to explicitly type a local variable?

With asm how to explicitly declare a variable parameter

How do I draw a shape and then declare it a variable?

How do I declare a variable in JSX?

How do I declare process type with Procfile?

How do I declare a object for use with this function

Why do people declare a variable of a base type of the object they assign to it?

How do I declare a member variable within the constructor that doesn't have a predefined type?

How do i declare a function which takes a variable of a yet unidentified type as parameter

How do I declare a type for array object using 'Pick' and '&' keyword at the same time in TypeScript

How do I check if the type of an object assigned to a variable is correct?

How do I know what type of variable to use for an instance of an object?

How do you declare the type a property of an object in-place, without needing to declare the type of the entire object?

How to declare a variable or Object of any class type in Java

How do I declare new type with type constraints in Haskell?

How can I declare an extern reference to a variable of type char** in Chapel?

How do I avoid conflicts between haxe Type class and C# Type class?