wing
wing copied to clipboard
Static field initialization
We don't support static field initialization yet:
class R {
static n: num = 5; // Error no support for initializing the static field
static m: num; // Error uninitialized static fields don't make sense
}
We do support static fields in the type system, so when importing a JSII library with static fields it'll work. But we can't create our own static fields yet.
We decided this is p2. See discussion here.
Hi,
This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!
Hi,
This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!
This would be great to support, but we should only allow this for constant data which is immutable data (e.g. primitives and immutable collections of primitives).
We should also support static immutable data in modules. Currently modules do not support top-level let
statements (or any statements), but we should make a special case for this type of constants.
@Chriscbr fyi
We should also support static immutable data in modules. Currently modules do not support top-level
let
statements (or any statements), but we should make a special case for this type of constants.
Also functions? Imagine a nanoid62.w
file:
bring util;
let alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
/* pub */ let nanoid62 = inflight () => {
return util.nanoid(
alphabet: alphabet,
size: 22,
);
};
looking for a way to reuse static immutable data in pre- and inflight. I think this would help here?
here's an eample in a module (config.w
)
bring cloud;
bring aws;
bring "@cdktf/provider-aws" as tfaws;
pub class Config {
// would be nice to share pre- and inflight, also as a static class attribute or something like this
// see https://github.com/winglang/wing/issues/1668
pub static key(name: str): str {
return "/wing-cloud/apps/config/staging/${name}";
}
pub static inflight keyInflight(name: str): str {
return "/wing-cloud/apps/config/staging/${name}";
}
// can't do static methods yet, see
// https://github.com/winglang/wing/issues/2583
pub add(name: str, value: str) {
new tfaws.ssmParameter.SsmParameter(
name: Config.key(name),
type: "String",
value: value,
) as Config.key(name);
}
pub inflight get(name: str): str {
return Config.fetchParameterValue(Config.keyInflight(name));
}
}
went with attributes in this case which are both available pre- and inflight. edit: To be clear: I haven't found a fix, it's just a workaround.
class Foo {
a: str;
init() {
this.a = "foo"
}
where a
is then available in preflight and inflight stages.
Hi,
This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!