winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
5.06k stars 198 forks source link

[Feature Request] Having a typeof operator in Winglang #4106

Open harsh9607 opened 1 year ago

harsh9607 commented 1 year ago

Feature Spec

I was wondering if we could have a typeofOperator like we have in javascript. We could have something like

let x  = 42 ;
log( typeof(x));

returns number;

Use Cases

https://www.winglang.io/docs/language-reference

It is part of Roadmap

image

Reflection: add an extended typeof operator to get type information.

Implementation Notes

It could be built upon the typeof operator of Javascript.

Component

Language Design

Community Notes

staycoolcall911 commented 1 year ago

@MarkMcCulloh, @tsuf239, @hasanaburayyan, @Chriscbr - would you suggest implementing this similar to:

  1. util.sleep()
  2. Our built-in log()
  3. Any other suggestion on how to implement this?
ekeren commented 1 year ago

I am not sure we want to implement this without a broader discussion of reflection and also typeof in javascript is not compatible with strongly typed languages... (where the typeof bucket could be cloud.Bucket or maybe some IBucket - thanks @Chriscbr )

hasanaburayyan commented 1 year ago

Yea I think for sure its something that would be useful to have and we probably want it. However, its kinda complicated because of the way typeof works in javascript. Maybe we add this to an upcoming team time discussion? Im not sure how exactly implementation would work, somehow we need to map the javascript back to the Wing type.

staycoolcall911 commented 1 year ago

Makes sense - I'll add to a next team time so we can discuss it. Marking this issue p3 in the meantime.

Chriscbr commented 1 year ago

@ainvoner After re-reading this issue, if I understand it correctly this might be a separate feature from the typeof type operator that TypeScript introduces for use inside type annotations and type parameters (e.g. someFunc<typeof otherFunc>()). Their docs explains it better than I can https://www.typescriptlang.org/docs/handbook/2/typeof-types.html

github-actions[bot] commented 11 months ago

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!

github-actions[bot] commented 9 months ago

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!

github-actions[bot] commented 6 months ago

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!