-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
dtypeof = typeof, but ignores all inferred types from assignments' that reference this object keys. More concise & constant behaviour #24517
Comments
I can't really understand what you're saying. Furthermore, I can't reproduce the "current undesired behavior". This is what happens: const overideString: string = object.c; // error
const overideNumber: number = object.b; // error
var object = {
a: 23,
b: 'sdfsfd',
c: true,
d: false
}
type TObject = typeof object
/*
type TObject = {
a: number,
b: string,
c: boolean,
d: boolean
}
*/ You can't mutate the type of a value from |
In addition, the compiler can not really tease out sources of property declarations from a type after it is formed. |
@jcalz, Sorry if this was a miss understanding, this wasn't meant to be taken so literally. It was merely to act as a simplified example to communicate the behaviour we have observed, in our much more complicated type manipulations, we are performing. Clearly if taken literally then you are 100% right. Lets say our work around for this behaviour to stop it happening was to simply extract our typeof operator usage into a single file and then export them. Because then the indirect reference behaviour which could change a type definition is contained to the same file in which typeof is used. I hope that this finds you in the best interest of the ecosystem. |
I am not really affiliated with the language maintainers and have no special influence with those who are, so I doubt it would help much if I were to ask someone to investigate. Furthermore I still don't understand the issue, nor do I understand how to interpret code in a non-literal way (maybe there's a |
Then how are you suppose to vet issues like this? Surely you should have a procedure on how to handle task and esculate this issue, until it finds it way up the hierarchy of knowledge to someone who is capable of dealing with this level of request... Or weather the request should become a TC39 issues and handle by one of the comity/community members who implemented the features...?? |
I am a frequent shopper at this grocery store. You are another customer having a problem with an item you purchased. I wanted to be helpful; maybe I could point you toward the aisle that contains a more acceptable product. But unfortunately I don't understand what your problem is: you left the relevant item at home and your verbal description doesn't make sense to me. At this point I say I don't think I know how to help you and try to continue my shopping. But you start following me. I tell you: "I don't work here." But you are upset about your item and my lack of helpfulness, and keep following and complaining about the store. Maybe you think I secretly do work here? Or that I should have done more as a fellow customer in the interest of consumer solidarity? I don't know, but I'm beginning to worry. I walk faster, calling back to you over my shoulder: "Sorry, but I really don't work here and I don't think I can help. Good luck!" I turn a corner, then leave my shopping cart at the end of the aisle, and quickly hide behind a display case so you won't see me if you keep trying to follow. It's paranoid, I know, but I can't help it at this point. Okay, I need to just calm down and move on with my day. Besides, you're not really following me, right? Fine, great. Still, instead of confidently striding back to my cart, I cautiously peer out past the edge of my display case to see if you're waiting for me. What do I see? |
Since I don't think this conversation is going to become constructive, I'm going to lock this issue. |
dtypeof is suggested new keyword that performs a semantically similar operation as typeof, however, ignores all inferred types determined from assignment which reference the object keys that typeof operates on.
typeof allows one to do many advanced and great things with the types engine, but they are subject to inferred types constraints, that reference the objects keys, were an inferred alternative manual type constraint, then overides the typeof that we are really interested in.
Generally speaking this is only a problem when someone wants to reference an object upon, which one performed the typeof operation on, as it then changes the typeof signature, every where potentially in ways that are not ideally to the behaviour we were looking for, which should be constant and not changed indirectly by someone referencing a key with an assignment operator that has a type constraint, which then infers a different a type, changing the results of the typeof operator, which could be see as unintentional and by mistake or break existing dependancies.
This typically I would imagine that one would want the more predictable behaviour of the function type of under a different name dtypeof
UseCases And Examples Behaviours
Typically usage
Current undesired behaviour
Wanted constant behaviour with using dtypeof
Wanted constant behaviour with using dtypeof, even with type constraint
Structural constrains to constrain setup of objects or return of function method type signatures
were dtype is a type to be determined at runtime by type inference. We current use this pattern to achieve some really cool dynamic types using generics, instead of having to have preprocesses that generate the types for you.
Recursive type entry evaluation, for different use case and feature to be cognisant of when implemented this feature improvement of dtype.
What be even more cool, is if typescript support Generic recursion, because then could pose a different set of types constraints on const object initialisation that what we get out.
This can partially be done with classes, however, the compiler doesn't constrain the class definition by the defaulted T ='T' for each definition or a variable declaration that use T, so that when assigned in the class definition, it must match the evaluated type specified by T ='T'.
If this could be done it would be really great too.
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: