-
Notifications
You must be signed in to change notification settings - Fork 1
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
Sound wrong to me #1
Comments
I think the idea of this proposal is to standardize type syntax. similar to how python has types but the interpreter just ignores them https://docs.python.org/3/library/typing.html given that flow and ts already share very similar type syntax ( |
Sounds perfectly reasonable to me! JavaScript already ships with types! Few people notice: @lifaon74 TC39 is all about JavaScript standards, if we are talking about the possibilities outside JavaScript, it's off topic in TC39 IMHO. @obedm503 Precisely! There is no need for JavaScript to reinvent the wheel, take clues from how Python does it, stand on the shoulders of giants! @samuelgoto I think creating a bridge to fill the gap is genius engineering, well done 🎉 REPL examples: const obj = 1.42;
Type.fromInstance(obj)
// Number() Just musing, though one can then even have a new Type(Number | Promise)
// UnionType(Number, Promise) |
@keyvan-m-sadeghi
everything in JS aready inherits from |
@obedm503 typeof 1.42
// "number"
typeof new Promise(resolve => {})
// "object" In fact, now that you brought it to my attention, Object.type(1.42)
// Number()
Object.type(new Promise(resolve => {}))
// Promise() The difference here is that an By acknowledging that JavaScript already has function aFunction(aNumber: Number, unknown: Object): Promise {
// function body
} |
Wow, wow, wow, Number, String or Promise are not types ! They are functions/classes which allow to create instances or cast a type to another. Moreover using Notice than What i'm pointing in my top first argument, is that types for javascript are far far more complicated than you could imagine due to the versatility of javascript, no spec sheet would be able to cover it a the first round, probably hundreds will be needed. Typescript add an huge amount of improvements for each of its releases which appends frequently. Integrating types at the level of TC39, would be really longer and error/regression prone. Some types are pretty hardcore, as an example: |
@lifaon74 Now that we're at it, give this a try: typeof (new Number(2) + new Number(3)) You have decided to call it a bad practice, it's perfectly valid JavaScript. Historically, JavaScript incrementally integrated concepts like
note Substitute "standardized" for "invented" , since that's what's really happened About your note on hardcore types, you are absolutely right. Even |
@keyvan-m-sadeghi Now, if BUT maybe you wanted to express something different, something not currently in the definition of this proposal (as i understand it). In this case, don't hesitate to create a new issue, this one is not intended to discuss about Object.type, but to point the hardness of such a proposal where typescript for example do it just right. |
I'm a big user of typescript and I'm not convinced at all by this proposal:
It start with a good idea: "everybody should be able to use types". But in reality, it's already the case... (except its not native, but the transpilers add far more than just types...).
PS: I really encourage people to use typed js with a good IDE which helps A LOT debugging, maintaining, avoid a lot of errors, and provide powerful auto-completion. But I would not see this natively in JS.
The text was updated successfully, but these errors were encountered: