News for hackers. Stuff that matters.
Re:A one-line package broke `npm create-react-app` by degraafc on Saturday April 25, 2020 @01:40PM (#22979731)
I'd say that it should rather be a part of the type system. Some kind of `obj isa Promise` should be the way to do this, not random property checks. But that's JS...
Re:A one-line package broke `npm create-react-app` by kroltan on Saturday April 25, 2020 @01:50PM (#22979790)
The thing is that there is the Promise "class", which is provided by the environment, but there is a interface called PromiseLike, which is defined as having a method called then that takes one or two functions. Now, JS doesn't have nominal typing for interfaces, so you have to do "random property checks".

Typescript partially solves that by declaring types, but if you have a any variable, you still need to do some probing to be able to safely convert it to a PromiseLike, because TypeScript goes to great lengths to not actually produce physical code on its output, attempting to be just a type checker.

Perhaps if TS or an extension allowed "materializing" TS, that is `value instanceof SomeInterface` generated code to check for the existence of appropriate interface members, this could be avoided, but alas, this is not the case.

Re:A one-line package broke `npm create-react-app` by ehsankia on Saturday April 25, 2020 @01:59PM (#22979882)
shouldn't it then be called is-promise-like? Also, if you're being loose about it anyways, can't you simply just go for `if (obj && typeof obj.then == 'function')` and call it a day? I'd say that's short enough to include your own version and not rely on a package for.

I think that module over complicates it as it is, and most people don't need that level of complication in their code.

Re:A one-line package broke `npm create-react-app` by zbentley on Saturday April 25, 2020 @03:20PM (#22980586)
> Perhaps if TS or an extension allowed "materializing" TS, that is `value instanceof SomeInterface` generated code to check for the existence of appropriate interface members, this could be avoided

It's not perfect and a bit of a bolt-on, but io.ts works reasonably well in this area:

https://github.com/gcanti/io-ts

Re:A one-line package broke `npm create-react-app` by odensc on Saturday April 25, 2020 @01:43PM (#22979750)
In theory `x instanceof Promise` would work, but the reason for this package is that there are many non-standard Promise implementations in the JS world.
Re:A one-line package broke `npm create-react-app` by exogen on Saturday April 25, 2020 @05:43PM (#22981814)
It wouldn't work even if everything were native – see my reply above.
Re:A one-line package broke `npm create-react-app` by odensc on Saturday April 25, 2020 @07:02PM (#22982421)
That applies for browsers, yes (though I'd argue is a rare edge-case), but create-react-app is a Node.js application.
Re:A one-line package broke `npm create-react-app` by exogen on Saturday April 25, 2020 @08:10PM (#22982869)
create-react-app isn't even using is-promise directly. It's several hops in the dependency graph away.
Re:A one-line package broke `npm create-react-app` by city41 on Saturday April 25, 2020 @03:40PM (#22980762)
Promises were not always part of the standard and for many years were implemented in user space, by many different implementations. Using duck typing like this was the only way to allow packages to interact with each other, as requiring an entire stack to say only use Bluebird promises is not realistic at all.
Re:A one-line package broke `npm create-react-app` by staticassertion on Saturday April 25, 2020 @01:42PM (#22979743)
I'm totally with you on this. It's dumb that this is a problem but it is actually a problem.