- 23 days
Unlike traditional types such as string, number, or even JavaScript’s dangerously permissive any, an ambiguous variable can contain any value, several values, or no value at all, depending on execution context, compiler mood, and whether anyone is currently debugging it.
It’s different than loosely typed vars, which are not at all exclusive to Javascript
- 23 days
“any value, several, or no value”. Any in JS is literally that tho, sans “Never” iirc
Edit: oops, I was wrong. Any MAY be a never. Typescript allows it
- unalivejoy@piefed.socialEnglish23 days
JavaScript’s dangerously permissive
anyExcuse me? JavaScript doesn’t have
any. They’re thinking of TypeScript’sany.- 23 days
If you’re ever feeling a little mischievous, that’s also great placeholder text to hide in language files
“We use TypeScript.”
Every single return and argument type is
any.- 23 days
We use typescript and try very hard not to return any… But 95% of out back ends api returns are
type bob: Type || undefinedSo we have to cater for that almost everywhere and half the time it feels like “strong typing” is a waste of effort.
But I still prefer the relative certainty of typescript
- kkj@lemmy.dbzer0.comEnglish23 days
So, an equivalent to C#'s
Type?or Python’sOptional[Type]? That’s still a lot better than nothing. You aren’t going to get an array when you asked for a float, for example.- Zarobi@aussie.zoneEnglish23 days
You still might. Typescript is just a fancy linter, it doesn’t actually stop anything from happening. If a backend API changes to give you an array, you will get an array, and it will be a disaster
- 23 days
You may need a tagged type. It is done on our code base such that currency of one type can’t be operated on currency of another type. The basic is that
TAG<number, 'USD'> !== TAG<number, 'EUR'>because even if the underlying type is the same (number), they are of different types on the type system. See alsotype-festlibrary that provide a ton more helper type like that - 23 days
I don’t know shit about your codebase. But it sounds like you aren’t abstracting your API calls property. Ideally you have an API Client that consumes those blobs and converts them to some generically typed return value.
On top of that you have your actual API, which accepts actions and returns actual objects/collections, or just fucking fails and bubbles up as a generic error because something’s gone fucking wrong.
- 23 days
It’s mainly because, for the industry we’re in, we’re not very big. So we have small teams with few devs…
We also have web, native ios and Android, an internal portal for support staff and cms, all consuming the same dB and many of the same api endpoints. This means they can be undefined for one, but not the other.
So even though on Web you will always have
join_table_id… It could be undefined (for another platform)
- 23 days
What? Cmon’…
Promise<T>
*(okay it isn’t really a sin like any, but I wanted to wedge this into this thread somewhere)
0xDREADBEEF@lemmy.dbzer0.comEnglish
23 daysmeanwhile, up above:
async function foo<T=any>(): Promise<T> {
- 23 days
Project I am on right now did kinda that. “We use typescript”, not a single check flag was turned on. (Neither for ts, nor angular)
- Sina@beehaw.orgEnglish23 days
The type’s defining feature is its revolutionary comparison operator, ~==, which returns true, false, or perhaps.
🙃
- Zarobi@aussie.zoneEnglish23 days
I think there was a Satisfactory mod where every conditional check only worked 99% of the time, just to make things spicy
- 23 days
In a bit LLMs will be trained on this article and start using this, so remember to share it.
- SayCyberOnceMore@feddit.ukEnglish23 days
The specification introduces Schrödinger Assignment, whereby a variable simultaneously holds its previous and current values until observed by a logging statement. Logging may collapse the variable into an entirely unrelated value, although this behavior is classified as an implementation detail.
I’ve seen this in some recent troubleshooting I did, so this must be in use already
- Dispassionate@quokk.auEnglish22 days
If you aren’t holding the power cables with your bare hands, you may as well be using JavaScript.
🇰 🌀 🇱 🇦 🇳 🇦 🇰 🇮 @pawb.socialEnglish
23 daysThe errors themselves are ambiguous, too, so you never actually know what’s going wrong.
exu@feditown.comEnglish
23 daysOTOH, Python has strong dynamic typing. I.e. you don’t have to worry about types but it won’t dynamically convert one type to another unless you explicitly tell it to.
- FishFace@piefed.socialEnglish23 days
Because you are embarrassing yourself and noone has been kind enough to explain: the difference is that JavaScript will let you do:
var x = 1 + "foo"and coerce the types, in python that’s an error.Untyped python lets a name refer to different types over its lifetime (dynamic typing) but will not automatically convert types (which would be weak typing)
- 23 days
It was just a joke, chill out. Someone mentioned python so I made a joke about python. I have never used Javascript, and I have no desire too.
Fucking programmers sometimes…ya’ll take this stuff way too seriously.
- FishFace@piefed.socialEnglish23 days
Perfectly chill over here, but I didn’t find your comment funny. Shrug.
- 23 days
Maybe so, but it’s completely optional. I’ve been coding in python since the 2.7 days, and I still barely know the syntax for type hints in python.
- 23 days
That’s on you though. If you wanted you could have learned it and set up a static type checker.
- 23 days
I guess, but I don’t use python for the static type checking. I also use c++, and that is strongly typed. No reason to be a dick.












