-
Notifications
You must be signed in to change notification settings - Fork 12.8k
allow type declarations inside objects #8308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
so namespace expressions, a la class expressions? |
please allow either of the following:
|
here is a sample: function toModule<X, Y, Z>() {
return namespace {
export interface W { x: X; y: Y; z: Z; }
}
}
const m = toModule<string, number, boolean>();
const w : m.W = { // <-- wish could do that
x: '',
y: 0,
z: false
}; |
both approach has issues with the current implementations that assumes an expression can only be a value, and not a namespace. we will need a proposal for this one. |
WorkaroundThis is the workaround that I have to use now: interface W<X, Y, Z> { x: X; y: Y; z: Z; }
function toModule<X, Y, Z>() {
const $W : W<X, Y, Z>;
return {
W: $W
};
}
const m = toModule<string, number, boolean>();
const w : typeof m.W = {
x: '',
y: 0,
z: false
}; |
👍 |
that would be super great |
I am afraid that alone returning a namespace isn't enough. It needs to be also passed as an argument and taken as a parameter. In order to declare it it has to have a type. Do namespaces have a type per se? Doubt so. Anyway, I believe that the difference between namespaces and objects is a made up. It would be great to see namepaces unified with objects because to JavaScript they are the same. |
closing in favor of #8358 |
The text was updated successfully, but these errors were encountered: