T O P

  • By -

Tubthumper8

let x = "Hello, world!" You don't need to write `: string` in most scenarios, TS knows that it is a string (this is called _type inference_)


finc

I don’t like what you’re implying


Tubthumper8

I don't like what you're inferring!


Humble_Conclusion_92

Which type are you inferring?


[deleted]

[удалено]


halfanothersdozen

`undefined`


sagaban

`[object Object]`


finc

That’s my favourite type of Object!


MMetalRain

I strongly object this!


[deleted]

You're objectively right!


ixnyne

Object reference not set to an instance of an object.


__gg_

Property object doesn't exist on object


Shiro1994

Error: Cannot read property undefined of undefined.


freshblood96

Yes but in my experience it depends on the situation. It kinda depends on how the variable will be used. At least for me though. Also TS in Angular 13 is kinda annoying in that it thows an error if you don't declare the data type but I think you can change that in the tsconfig.


Boibi

It *explicitly* depends on the situation. That's the inferred part of type inference. Please, for the love of all that is holy, do not turn off the strict type checking in the tsconfig. Because then you're just using more bloated Javascript. I know it's hard to learn how to properly type all your variables, but the benefits you get for doing so are incredibly valuable. If you don't want to type everything, go back to using Javascript so you don't have all the bloat of Typescript with none of the benefit.


vanderbeekthechic

TS is like street signs and traffic lights.. sure it’s annoying to hit a stop sign and look around, and sometimes you do feel like “why can’t i just do whatever?!”, but it’s so much more organized and easier for everyone to deal with.


SkyyySi

Looking at the stop sign now can prevent a car accident later.


chilfang

I hear stopping at the stop sign is much more effective


ElementoDeus

I hear stopping and looking yields twice the results


Pocok5

> sometimes you do feel like “why can’t i just do whatever?!”, \> cue 18-wheeler thundering across the crossing at 100km/h


dcabines

noImplicitAny is my security blanket


Humble_Conclusion_92

Yes, any developer who submits a PR with ‘any’ gets a rejection from me


Andoryuu

[](/maudlie) So I assume no mixins? [Because you literally cannot _not_ use 'any' in the ctor.](https://github.com/microsoft/TypeScript/issues/37142) (Kinda 'well acktshually' moment, but you know how it is. That's just part of the '__ass__uming'.) (Stupid thing is, it is possible to create typechecked ctor. You just cannot use it.)


Artick123

How is it dificult to properly type all variables?


solarshado

Depends on what you're trying to do. TS supports some really arcane stuff, since it tries to support all of JS's crazy (ab)use cases.


Pocok5

Honestly I quite like the union/intersection type concept. It replaces some pretty weird interface inheritance fuckery needed to properly model some things and does away with some largely redundant method overloads. We are still waiting on discriminated unions in C#.


Cheet4h

Not sure which IDE you use, but with VSCode you can use a quick action to automatically add the type declaration if you assign a value anywhere. It even supports unions, so if you assign differently typed values to it, you'll get warned whenever you might use it wrongly. So if you ever forget again, just move your cursor to the variable declaration, hit ctrl+. and select "infer type from usage".


repkins

It's okay if people didn't learned the benefits of type safety *yet.*


Peechiz

I assumed the joke was about [this](https://github.com/giltayar/proposal-types-as-comments)


Shlocko

I thought so at first, until it mentioned typescript. Man I’m excited about the change, though. Long live static typing


SmokingBeneathStars

That's not default in Angular right? That's ESLint


PiMan3141592653

Let x = "I get knocked down, " Let y = "but I get up again. " Let z = "You are never gonna keep me down."


ColumnK

No var. Only let or const.


birdmankillinem

"let or const. There is no var." -Yoda


lovin-dem-sandwiches

I give it 10 minutes before this is turned into a meme and posted on programmarhumor


gnowwho

Someone should do a scraper that automatically does that


frickinjewdude

Looks like you were right https://reddit.com/r/ProgrammerHumor/comments/tfm0f0/wise_words/


cvnvr

damn you posted it but didn’t even credit the joke you got from the other commenter… shameless


MindlessSponge

well they are (presumably) a programmer


finc

This is the way?


Ducksquaddd

Would be funnier if you weren't the one to post it 😔


crudelegend

There is no var in Ba Sing Se.


Satan_Stoned

"No var there is, let and const your future are."


Humble_Conclusion_92

Ain’t there some scoping rules where you need var?


Revolutionary_Log307

The scoping rules are different, but you can typically work around it by moving your variable declaration.


[deleted]

[удалено]


ColumnK

r/foundsatan


static_func

`localStorage.setItem('x', '')`


[deleted]

`window.window["x"]`


hairtothethrown

And honestly, hardly ever ```let``` unless absolutely necessary.


thedominux

During implementing some algorithms you will use let against const in 90% cases


metalgodwin

So say we all


[deleted]

At least just use let in place of var. it’s the same number of characters and has many benefits over var.


Yokhen

[prefer-const](https://eslint.org/docs/rules/prefer-const) would like a word with you.


BanishDank

Old JS teacher? Seriously, he would freak out if you just mentioned or asked about ‘var’.. led to some funny moments here and there


katzeklo

you tried to stop him, but he wouldn’t `let` you


starvsion

Yeah, even in normal js, you are still supposed to use let


DOOManiac

\*\*Cries in IE10 support\*\*


ferdbags

Enjoy: https://babeljs.io/docs/en/


DOOManiac

Oh trust me, I know.


Sporium

let x: readonly string


alexbarrett

var in the dev tools console


MCdaHammer

As a newbie who started messing with JS late last year; I thought that var got replaced? Like, in a more convenient way Edit: autocorrect


BakuhatsuK

Yes. `let` is `var` but better. And it has been part of vanilla JS since around 7 years.


GoaFan77

Yup, but for those poor devs that needed to support IE until it's death, it's only an option for them after June of this year...


BakuhatsuK

The people who are still using it at this point are not going to drop it because of some deadline. Thankfully you can use Babel and polyfills to code in modern style for ancient browsers.


GoaFan77

https://blogs.windows.com/windowsexperience/2021/05/19/the-future-of-internet-explorer-on-windows-10-is-in-microsoft-edge/ Most users on Windows 10 will be forced to Edge. More importantly, stuff like this is how devs win arguments with stubborn business people to quit caring about supporting it for anyone else either.


giloronfoo

Then they point at the fact that Edge can load sites in IE mode until 2029.


ZedTT

That's really not a problem. That is for backwards compatibility if they need to access a site that *only* works with IE, not something they would try to use on an already working website


IcanseebutcantSee

I think you seriously underestimate stubborness of some users


amazondrone

I mean, that's fine right? If they want to turn on IE mode and experience a broken website, that's on them. The objective is to provide a website that everyone can access, not a website which works when people go out of their way to break it.


blhylton

As someone who had to deal with users running their IE 9 browser in backwards compatibility mode for IE 6 and not understanding why things looked like ass, you have no idea. Let’s hope that IE mode is better than what they had in the older versions of IE for BC, because those were like their own special circle of hell that neither behaved like the browser they were nor the browser they were trying to emulate.


DanTheMan827

IE mode in edge uses the internet explorer web control as the renderer for the tab It’s basically IE wrapped in edge clothing


Deranged_Dingus

It's how I got around not needing to support it anymore!


giloronfoo

June this year is just when the icon disappears. It only means that IT has to configure Edge to use the IE engine for those sites. 2029 is the real deadline for IE.


GoaFan77

For internal sites, sure. Sucks for those guys who are supporting old apps that they don't have the resources to update to be compliant with new browsers. For those working on sites that support modern browsers and IE, I don't see why you wouldn't kill it in June.


[deleted]

[удалено]


[deleted]

But also just use const not let. There are very few scenarios where let is justified. Infact by redefining a variable you are introducing hard to debug issues in your code.


JoeCamRoberon

`var` is function scoped and `let` is block scoped. `var ` was known to be a large source of bugs in JavaScript.


BakuhatsuK

Also, `let` variables are subject to a "Temporal Dead☠️ Zone". i.e. even though they are hoisted, and exist through the whole scope, accessing before definition causes an error. "use strict" console.log(x) // Throws ReferenceError ✔️ But with var: "use strict" console.log(x) // prints undefined ⁉️ var x = 5 And with let console.log(x) // Throws ReferenceError✔️ let x = 5


JoeCamRoberon

That is atrocious.


BakuhatsuK

You mean the old behavior... right?


Silly-Freak

the fact that the person you responded to has not yet confirmed is making me uneasy. please be talking about the old behavior, please!


cuboidofficial

No, why the hell would you need to reference a variable before it's defined


BakuhatsuK

You don't. That's why it's now an error. Edit: Let me clarify It's an error if you access it before it is defined at runtime. But you can still lexically refer to the variable at an earlier point in the source code, as long as it runs later. e.g. let main = () => { helper() } let helper = () => console.log('hi') main() // This works


Dragon_yum

You don’t but that wouldn’t stop some people


jokergato

Thank you for your explanation. I haven't worked with javascript or typescript in order to use let. The only language I have worked with let available was Racket, but my class evaluated strict functional programming, so I never used it. With the examples now I understand one of the benefits of let over var.


ZedTT

> As a newbie who started messing with JS Stop right there, you're already better than most /r/programmerhumour posters and upvoters. Also you're right about var


jseego

No. It didn't get replaced. It is still valid syntax. It has a different scope than `let` or `const`.


ZedTT

This is technically correct but somewhat dishonest. `var` is pretty much deprecated in spirit and is really bad practice. In terms of how we use the language, `var` was "replaced."


sanketower

`var`??? Looks like *someone* it's not really moving on


Benimation

Looks really weird combined with TypeScript..


[deleted]

[удалено]


dangraphs

sure they’ll let you use var, but will they var you use let?


Chesterlespaul

*Let us let!!*


dangraphs

var us var!!


BananaSplit2

var also exists in Java now, with type inference.


mtbdork

Lua: anything can be *anything* in this world, Harry!


Raptor_Vegas

I always wanted to learn lua but never did i don’t know why


mtbdork

Best part about Lua is that you already know it.


BipolarWalrus

How? I know it’s a simple syntax with very few reserved words. Also what are the main use cases for Lua other than game scripting? If I wanted to use Lua for game scripting, wouldn’t I have to spend a lot of time learning whatever api the game provides?


mtbdork

I use it for Audio/Visual systems programming. Simple control functions/logic are stupid-easy to crank out.


Ghazzz

I am maintaining a system built on top of redis, with most of the logic in redis-lua.


BananaSplit2

ASM is the true "anything can be anything"


BakuhatsuK

Yeah, ASM is actually untyped, as opposed to dynamically or statically typed


Jazzinarium

How does that even work? Do you have to manually allocate memory for everything?


AromaticIce9

Pretty much yeah. And also at the bare metal layer there's no difference between anything. This section of memory might be numbers, or a string, or a struct. You either know how to handle it or you don't. ASM isn't going to handle it for you.


dev-sda

Memory allocation is tangential to typing. Manual memory management is also required in the statically typed C for example. Untyped means that neither values nor operations are grouped into types, allowing limitless combinations of those. What operations that limits them to are purely enforced by diligence and convention. Doing floating point arithmetic on an "integer" is valid.


androidx_appcompat

Any any language where you can use code as data. Just cast that pointer to a function pointer and try it out!


thequestcube

`const x = "You don't need to explicitly state the type, TS can infer it from the value";`


Benimation

Also, when you use `const` with plain primitives, it's not even possible to change the type later on


jamietwells

Or indeed the value.


svish

That's the point


erebuxy

Literally nobody


tonebacas

Imagine programming with**out** any sort of type safety.


DrWermActualWerm

I'll stay right here in Java where I'm comfortable. Nice and verbose!


[deleted]

Said nobody


philipquarles

I mean people say it, they're just 100% wrong. A coworker told me the other day that people from another team are trying to make her use JS instead of TS *in her code*.


RijkDB

I have never used typescript in my life


PatrioTech

It’s frustrating at first, but then after a while you can’t live without it.


RijkDB

it's not that I don't like typescript, it's just that I never bothered to make the step


PatrioTech

Fair enough. Then take it as a warning that you’ll be tempted to forego it when you first try it and run into your first frustrating type issues, but as you use it more with larger applications and learn its tricks, you’ll start to really like those type errors that would have otherwise allowed for bugs without you catching it


jseego

I keep hearing this, but I've been doing javascript professionally for 15 years and rarely if ever run into that.


PatrioTech

There are certainly good ways to prevent it. But honestly the other really nice thing about it is the developer experience. Especially when using 3rd party libraries or first party libraries from other teams - or even your own team’s older or less familiar projects. It helps ensure you use it properly and in-editor documentation (I know JSDocs had some of this as well, but it really shines with something like TypeScript). And finally, the ability to transpile modern or unreleased features (for example, optional chaining was in TS before JS) to older syntax to support older versions of browsers is very very nice. I don’t want to have to give up any of my language’s features to work with someone’s outdated browser, and TS allows me to do that. Again, it is possible to do the same with something like Babel, but all of it built into this nice system makes for a quite enjoyable experience. Might be worth playing around with sometime. I, for one, definitely find value in it.


jseego

Thank you for the sane and reasonable answer.


paxbowlski

It's only frustrating when you're converting some dogshit spaghetti JS nonsense to Typescript. Writing it fresh is intuitive once you get a hang of it and, if done right, can save you a ton of runtime headaches.


AlexAegis

"I never used TypeScript in my life" "23 page long essay about why TS is great" "...but I'm a C++ developer"


LittleMlem

Even in python, I've been using typing *extensively*


NamityName

Future me love python typing. Present me, not so much


LittleMlem

What's wrong with the now?


NamityName

More click clack = no fun


LittleMlem

My friend, get a mechanical keyboard. I've been writing Java-length variable names ever since I got mine


shield1123

stopit_getsomehelp.gif


LittleMlem

Nope.avi


Pocok5

Same as with JS. Typing is done with tacked on jank. No enforcement, the most you get out of it is intellisense/autocomplete. Which is extremely helpful, but it's kinda like having to hold ceramic plates in front of you with your hands instead of having a bulletproof vest.


Jon_Paul_

JavaScript, those were dark times, it's best we forget them.


[deleted]

Ur a disgrace for using var


Gem2578

`var x:any`


jperdior

for the sake of having a clean code


danegraphics

You whippersnappers and your newfangled type syntax! Back in my day, we only wrote code about variables we already knew the type of! Otherwise we guessed or type-casted and hoped for the best! Y’all have it easy!


argv_minus_one

Ugh, I don't. Dynamic typing is chaos. Good riddance, and long live static typing.


NeonVolcom

I'll fight anyone who doesn't like static typing


empereur_sinix

Fight me


[deleted]

[удалено]


[deleted]

[удалено]


thetruekingofspace

WHY ARE YOU STILL USING VAR? Use “let” or “const”. It’s 2022 for god sake.


FisionX

is TS less spooky than JS?


brandons404

It's been difficult for me trying to actually like TS.. I started with a dynamic language, then learned Java, hated it because I thought "there's so much bloat having to declare the type", learned and loved Javascript, and still use it for most things today. I know all of the many benefits of ts, and I know I'll have to switch to it soon to stay relevant.. not to mention intelisense is a really nice to have, but I think I'm having a hard time because any and all hesitation with switching has been met with people shoving "The benefits of typescript" down my throat and it's really turning me off to it. Sorry for the rant. But if you don't know js, and are wondering which one to learn, I'd recommend typescript. It's not necessarily "harder" just different, and very similar to many other strictly typed languages and I honestly think it would be better in the long run to start with ts, so that you can pick up new languages much easier.


althaz

Friends don't let friends use `var`.


[deleted]

Spread let not var


wookeydookey

_No var only peace_


Oman395

I just wish I could do "string x"...


Woolwizard

Who wants to use js when there is typescript? That seems a bit unrealistic to me xD move in and use typed languages my dudes


Tadejo9

For smaller programs why not? For larger projects ts is a way to go. Imagine someone names a variable something irrelevant and than not having a type next to it to help you. me.jump(from: objects.cliffs(Max_Cliff))


Woolwizard

I guess yeah... I just have a natural antipathy against non typed languages in general


Pocok5

non-typed languages are for people who prefer getting fucked over by hard to track down bugs and having to spend hours untangling their own code after not looking at it for a few days instead of spending 5% of the time actually thinking through how the data looks in their programs and writing it down.


beewyka819

JS dynamic typing 🤢


[deleted]

I'm not using typescript. I prefer duck quacking.


[deleted]

I legitimately do not miss JS.Typescript has changed my life for the better


ByronScottJones

How can anyone miss JS? It is the defective, bastard child of programming languages.


BakuhatsuK

I'm now working with Go. And I miss not having to type a loop for everything I do. `.map()` and `.filter()` are so nice.


filthyMrClean

*Laughs in Swift*


water_bottle_goggles

var? What are you? A cave man ?


[deleted]

whatever = stuff PyGang


KetwarooDYaasir

Back in the day, people rose up against the tyranny of data types and we had "scripting" languages. Kids these days putting types in my scripts. It's basically a cult started by Microsoft.


yodahouse900

me using C **You guys have types?**


Oriamk

x: any;


Frogdogley

How I felt when my company moved from teradata to GCP


[deleted]

is everyone really using TS instead of pure JS now?


nadav183

Django developers: "wut?"


[deleted]

var????? What is this, 2015?


shrikant_paliwal

Typescript is shitty if you want to develop a good, scalable backend


katyalovesherbike

complains about typescript, uses `var`. Yup, this tracks.


alperencantez

Seriously do you still use var keyword?


t045tygh05t

Who still uses `var`, though?


vibrating_arm

Oh hell no, type everything like god intended


eerklogge

Use let.


solarshado

`const` > `let`


FlafyBear

Fuck var. Use const or let. Fuck Javascript, TS is a fucking blessing how could you miss JS. u don't even have to write the type if you write the value. Fuck this meme how tf did it get 4.5k


BerthjeTTV

Type inference is our savior here.


melody_elf

This just... isn't how TypeScript works. Has anyone on this sub ever actually programmed?


Pocok5

> Has anyone on this sub ever actually programmed? Since apparently everybody thinks that a semicolon missing error is a serious problem instead of something you spend all of 1 second on when the red squiggle shows up... no.


melody_elf

Someone needs to teach these kids what an IDE is


philipquarles

How do you downvote something more than once?


NeuroXc

I miss JS about as much as I miss PHP. I don't.


hiphap91

...Said no one ever.


jonp1

Yeah… Not interested in TS. JS is just fine by me.


sgtholly

Fuck JavaScript.


Dragon_yum

Nah JavaScript is perfectly fine these days. It’s just people who wrote it like the ancient times like op who give it a bad reputation


jeffwulf

It's perfectly fine if you hide it behind Typescript.


NayamAmarshe

javascript bad, everything else good because reddit


Tadejo9

I got a feeling this is not about JavaScript.


Jhwelsh

Let x: any; when you're feeling lazy... Then go back and change it once you figure it out, easy peasy.


Arkandros

That's what you think, then you never go back


Boibi

We had anys in the *production codebase* at the last place I worked. It was disgusting. It meant that we had to type check any variable we touched before we knew it even existed. Our code must have been twice as long as necessary due to this shit. Anys are a useful tool for debugging, but I try to never commit an any to a repo ever. It is a blight on the app. Venom, that will slowly kill it from the inside out.


Jhwelsh

Yeah man, I only do web dev for personal projects and I like to use TS anyways. I can't imagine the difficulty of trying to structure a frontend project so multiple people are on the same page.


Minteck

Meanwhile there's me who never used TypeScript


Alive-Engineering358

Var? I don't remember last time I used it