-
Notifications
You must be signed in to change notification settings - Fork 12.8k
unify namespaces and objects #8358
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
so what is the proposal? and how is it different from #8308? |
proposal goes: make namespaces first class citizens, which is
they are different in a scope of work, #8308 is (hopefully) less work and because of that might win over this request |
i am guessing you mean define a parameter as a namespace, you can pass them now just fine. |
not sure what you mean: namespace N {
type T = string;
}
function f(n: typeof N) { // <-- ?
return <n.T> undefined;
} |
the value N (the object literal equivalent) does not exist. so |
I still do not see much difference and/or proposals than #8308. i would rather have one issue. |
which one is more likely to be implemented this (unifying objects and namespaces) or #8308 (adding types as pseudo-properties of objects)?
can you show an example of passing a namespace as an argument? |
namespace N {
export var x = 0;
}
function f(n: typeof N) {
return
}
f(N) // OK
f({ x: 0 }); //OK
function f2(n: { x: number }) {
return
}
f2(N) // OK
f2({ x: 0 }); //OK |
OK, so there is a value, i.e. the entity that exists at runtime in JS, there is a type, i.e. the design time construct that is defined in a TS file, and there is a namespace, something that can contain, values, types and other namespaces. a name can have 1, 2, or all 3 meanings based on its declaration. so a class is both a type and a value. an enum, is a value, a type, and a namespace, etc.. you can read more about this at: http://www.typescriptlang.org/docs/handbook/declaration-merging.html
this is what i meant by askign for a proposal on how this would fit in the existing de# #8308 (comment) I think the two issues are the more or less the same issue, and a clear and detailed proposal is needed. marking this issue as a duplicate. |
i am closing the other one (#8308) then |
#420 seems vaguely related for the record. The thing is that there is no value side to non-instantiated namespaces. Something like namespace n {
export interface Foo { }
} doesn't actually have any associated emit, so it's not clear what you'd pass in for a function like function foo(x: typeof n) {
// ...
} Does foo(n); compile to the following? foo(undefined); |
practically (as far as i know it) i only pass types and values (never types alone), although it is a valid question, need to find a use case that does it |
side note, you don't need to pass types-only namespace, you can make it on site as you want:
|
Uh oh!
There was an error while loading. Please reload this page.
Namespaces are objects that can hold types, but cannot be passed around because don't have a type themselves.
Objects are mostly namespaces which can be passed around because they are typed, but cannot hold types in them.
Looks like this difference is a made up thing.
Consider unifying objects and namespaces.
possible resolution of #8308
The text was updated successfully, but these errors were encountered: