Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any plan/interest to rewrite in TypeScript? #321

Closed
mgcrea opened this issue Jan 21, 2021 · 9 comments
Closed

Any plan/interest to rewrite in TypeScript? #321

mgcrea opened this issue Jan 21, 2021 · 9 comments

Comments

@mgcrea
Copy link
Contributor

mgcrea commented Jan 21, 2021

Seeing that got is now 100% typescript, is there any plan or ongoing effort on porting this sister project to TypeScript?

@sholladay
Copy link
Collaborator

I'm personally on board with this. It would certainly be nice for Deno users, as it would remove the need to manually import the types.

@sindresorhus
Copy link
Owner

I'm not sure I want that. The Got rewrite to TS ended up being a nightmare. TS just so buggy.

@sindresorhus
Copy link
Owner

as it would remove the need to manually import the types.

Why would you need to manually import the types? Can Deno really not infer it automatically?

@sholladay
Copy link
Collaborator

sholladay commented Jan 22, 2021

Deno imports modules directly from URLs. They have an excellent on-disk caching system so things get loaded from the file system when possible but they've made a design choice to not probe servers for .d.ts files for every new .js request. I get it, honestly. Those HTTP requests aren't free and lots of JS libraries don't have built in .d.ts files.

There is an HTTP header that CDNs can use to explicitly point Deno to the TS types and it will then load them automatically. That's what the ?dts query parameter on the Skypack CDN does, which we recommend to Deno users in the readme. So I wouldn't say this is a big deal. But it would be nice if Deno users could just load an index.ts file from any CDN and not have to worry about those details.

@mgcrea
Copy link
Contributor Author

mgcrea commented Jan 22, 2021

I'm not sure I want that. The Got rewrite to TS ended up being a nightmare. TS just so buggy.

I can't attest for the ongoing maintenance burden of got as a TS project but as someone who was pretty reluctant to migrate both personal projects and published libraries to TS, I really find that it ends up being a pretty big net positive in both development speed and overall robustness of the code.

Also since ky does not have any dependencies and the dom/fetch related APIs must be pretty stable now. I don't think there would be much external TS-related burden.

Anyway, as maintainers it is your call to make. But if you do consider it in the future, I could spend some time on it, give it a try and see how it goes.

@sindresorhus
Copy link
Owner

There are multiple things:

  • TS broke something in pretty much every minor release (from talking to people, this is a common occurrence).
  • Node.js types are often outdated or incorrect. The situation might be better for DOM since it's now auto-generated.
  • Tooling is annoying. We cannot move to ESM because AVA (test runner) doesn't yet support ESM with TS.
  • Bloated package because of all the d.ts files.
  • The types aren't compatible with CommonJS got#1137
  • We have encountered a myriad of TS bugs where we end up on an old unresolved issue on the TS issue tracker. A pretty common occurrence.
  • TS is not even type-safe. They're only finally getting around to making array[1] include undefined.

Yes, there are obvious benefits too. TS linting has helped fix a lot of code. Refactoring is so much easier. Automatic .d.ts types. Etc.

That being said. Ky is considerably simpler than Got, so if any of you feel strongly about this and are willing to do the work, I will not be in your way.

@Richienb
Copy link
Contributor

Richienb commented Feb 4, 2021

How would we type deepMerge?

ky/index.js

Lines 24 to 53 in 110aba8

const deepMerge = (...sources) => {
let returnValue = {};
let headers = {};
for (const source of sources) {
if (Array.isArray(source)) {
if (!(Array.isArray(returnValue))) {
returnValue = [];
}
returnValue = [...returnValue, ...source];
} else if (isObject(source)) {
for (let [key, value] of Object.entries(source)) {
if (isObject(value) && (key in returnValue)) {
value = deepMerge(returnValue[key], value);
}
returnValue = {...returnValue, [key]: value};
}
if (isObject(source.headers)) {
headers = mergeHeaders(headers, source.headers);
}
}
returnValue.headers = headers;
}
return returnValue;
};

@Genarito
Copy link

Genarito commented Feb 4, 2021

Even if you put some general type as any[] for sources you could get some benefits like removing Array.isArray(...) as Typescript is checking that.
With a fast check I could say that:

  1. headers: {[key: string]: string}[]
  2. sources could be force to be always an array, so you could prevent the isArray/isObject if/else as it's used internally. But the recursive part should be removed. It would be cool if there were JS docs about what's doing that function

@sindresorhus
Copy link
Owner

Fixed by #330

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants