5

WHO THE FUCK THINKS
THIS SHIT
TS:
```
const a = function(callback: (err:any,data:string) => void):void{
callback(null,'balls');
}

a(function(err:any,data:string){
console.log(err,data)
})
```

IS BETTER THAN THIS
ES6:
```
const a = function(callback){
callback(null,'balls');
}

a(function(err,data){
console.log(err,data)
})
```

kys

Comments
  • 5
    So there are still people using the function keyword for lambdas.
  • 1
    Anyone working at intelliJ pretty much. Linter/intellisense devs.
  • 8
    What's wrong with specific types?
    Yes, it is objectively better.
  • 7
    It IS better, because you don't infer what's it going to return - you straight up tell devs to prevent/extend dependency on what function shall return.

    Also, pissing on type-safe arguments in 2022 be like...

    Alright "err: any" is very ugly - but that's because it doesn't commit anything good to DX.
  • 5
    it obviously is.

    however, both are equally inferior to an _actual_ strongly typed language. (TS, in the end, is just JS with extra steps)
  • 7
    Having worked with every version of javascript since 1.0 in netscape 2 I live the explicit types.

    Sure, for 10 likes it looks more convoluted but when your in the thousands of lines from a dozen developers those types along with intellisense and linting helps immensely to prevent bugs.

    And with type inference you often end up not needing to specify the types all that much and you get all the benefits.

    But especially intellisense gets a lot more powerful with real typing.
  • 0
    @Voxera 🙌

    @Oktokolo function() {} and () => {} are not quite the same
  • 1
    @PonySlaystation no, but that is not typescript vs js differences.

    Just because a dev writes bad code in a language is not necessarily the fault of the language.

    That example was not really good TS code so I focused on the actual TS specific differences.
  • 2
    @PonySlaystation Sure, there are subtle differences... which don't matter in the non-freak lambda use cases.
  • 0
    a(data => {
    console.log(data)
    })

    a("some_stuff", (err, data) => {
    console.log(data)
    })

    a((err, data) => {
    if (data.done)
    console.log(data.result)
    })
Add Comment