Structs
Structs are custom data types you can define to store structured information. They're loosely modeled after typed JSON literals in JavaScript.
main.w
// Define a simple structure called `Example`
struct Example {
a: str;
b: num;
c: bool?;
}
// Define another structure called `MyData` that includes composition
struct MyData {
a: str;
b: num?;
c: Example;
}
// Creating an instance of `MyData` with some fields initialized
let data = MyData {
a: "hello",
c: {
a: "world",
b: 42,
}
};
log(data.a);
log(data.c.a);
log(data.c.b);
Wing console output
# Run locally with wing console
wing it
hello
world
42