Giter VIP home page Giter VIP logo

Comments (13)

angus-c avatar angus-c commented on May 18, 2024 12

First 14 definitions added

from just.

ilearnio avatar ilearnio commented on May 18, 2024 2

I agree that there's no need to rewrite just in TypeScript. But adding TypeScript definition files into every just package makes a lot of sense. Since right now I'm unable to use just in my TS project as it lacks these definitions, and TS strict mode doesn't allow me to use packages without definitions.

For example, see how it is done here https://github.com/sindresorhus/is-plain-obj

And as a bonus the packages would get this badge on NPM website :)

image

from just.

ilearnio avatar ilearnio commented on May 18, 2024 2

@angus-c There seems to be no built in way in TypeScript itself to test typings for pure JS projects, see microsoft/TypeScript#7661.
However there is this testing tool that perhaps may help https://github.com/ai/check-dts.

Alternatively, I would go with simply adding some types.test.ts files that would look like so:

import pick from 'just-pick'

// Incorrect usage

// @ts-expect-error
pick([])
// @ts-expect-error
pick()
// @ts-expect-error
pick({ foo: 'bar' }, 123)

// Correct usage

pick({ foo: 'bar' }, ['foo'])

So whenever such files compiled with tsc they should not produce any TS errors.

from just.

jednano avatar jednano commented on May 18, 2024 1

@angus-c I love your response, even though I have a different mindset. I can tell that you read the whole post and carefully responded to every point I made. Respect! 🙇

I don't have any more ammo to bring to this conversation, so it looks like I'll have to fork it myself if I want to take it in this direction. I'm going to close the issue, but thanks for listening!

from just.

angus-c avatar angus-c commented on May 18, 2024 1

But then I have to transpile this because of ...rest. I'm actually trying to use almost exclusively ES3 (Object(keys) is an exception) for perf reasons.

from just.

jednano avatar jednano commented on May 18, 2024 1

FWIW, I created a separate project, Queso that is in a similar spirit as Just, but 1st-class TS support.

from just.

angus-c avatar angus-c commented on May 18, 2024

Hi Jed, thanks for the issue and I appreciate you taking the time to make it thorough and well-reasoned.

I agree that TS usage is growing and I'm pretty sure there are a section of developers who would be more likely to use Just if it had a typed interface. However I'm still not sure it's necessary to write Just in TS in order to use it in JS. As you can probably guess I'm pretty obsessive about perf and size impacts of every line of code in Just, so I'd want to check each PR carefully and see how it compiles to JS, which is a lot of work. Also while I take your point that transpiling will only marginally increase the shipped size, it will also require source map generation. The bare bones simplicity of the current set up has made the development / debug experience a joy and I'm wary about losing that.

There are already 3 Just module definitions in DefinitelyTyped and I'd more than welcome additions to that repo. I know that doesn't address your points 2 and 3 above but I do think it would open up Just to TS users.

from just.

jednano avatar jednano commented on May 18, 2024

I just wanted to give you a taste for what an actual PR might look like. See a093c6d

Make sure to expand the object-omit/index.js file to see the relevant diff.

- module.exports = omit
-
/*
  var obj = {a: 3, b: 5, c: 9};
  omit(obj, ['a', 'c']); // {b: 5}
  omit(obj, a, c); // {b: 5}
  omit(obj, ['a', 'b', 'd']); // {c: 9}
  omit(obj, ['a', 'a']); // {b: 5, c: 9}
*/
-
- function omit(obj, remove) {
+ function omit(obj, remove, ...rest) {
  var result = {};
  if (typeof remove === 'string') {
-    remove = [].slice.call(arguments, 1);
+    remove = [remove].concat(rest);
  }
  for (var prop in obj) {
    if (!obj.hasOwnProperty || obj.hasOwnProperty(prop)) {
      if (remove.indexOf(prop) === -1) {
        result[prop] = obj[prop];
      }
    }
  }
  return result;
}
+ module.exports = omit;
+ //# sourceMappingURL=index.js.map

from just.

angus-c avatar angus-c commented on May 18, 2024

@ilearnio yeah I'm leaning towards that solution. Happy to accept PRs if you want to start the ball rolling btw :)

BTW there are also some TS definitions for Just modules in Definitely Typed.

from just.

angus-c avatar angus-c commented on May 18, 2024

@ilearnio can I validate my .js file against a TypeScript definition file? It seems like I should be able to use tsc my.js --checkJS, but apparently this only works if the file includes jsdocs, which seems surprising given that a TS definition file can be generated from jsdocs.

from just.

jimmywarting avatar jimmywarting commented on May 18, 2024

I advocate jsDoc instead of TypeScript.

  • You can get same level typing support (even without jsdoc - depending on how you write your code - default arguments / class properties helps)
  • Don't have to transpile anything
  • run much faster
  • Fewer dependencies
  • Less configuration
  • Can be imported from browser
  • fewer files - downloads faster
  • Sometimes TS makes it much harder to read
  • Don't need any build process
  • No need for SourceMap
  • TypeScript is not standard (any valid javascript is also valid typescript - but not the other way around...)
    • uses public/private instead of #
    • enums
    • decorators
  • Can't simply copy paste anything and have it run instantly in the browser or onto some other JS only project.
  • Always stays in the shadow of javascript - will always be one step behind new features
    • can't use private class methods for example #foo() { ... }
    • just tried to use addEventListener(evt, fn, { signal }) and it complains about signal cuz it's not up to speed.
  • there is nothing wrong with a loosed typed language
    • TypeScript is really bad at this. You are allowed to do many loose hacks that TS have hard time to graps. It's perfectly fine to add 1000 to a Date object and get a number back. Or add one to many argument to a function that only accepts 3, Blob parts are not restricted to only string, typed arrays and blob, it accepts anything, cuz the default behavior is to cast any unknown object into a string, same thing with Response, Request, FormData, URLSearchParams unknown arguments gets casted to a string but TS complains about this. It throws if you try to do fetch(new URL(str))

I love typing and i support it too (with jsdoc+followJs) but i hate the syntax cuz it's not vanilla javascript - all of you who comes from java, or .NET or any other typed language and don't want to learn vanilla javascript, stick with what you know and transpile it to web assembly instead. I also love our beloved loosed typed language - it's not a bug, it's a feature!

@angus-c There seems to be no built in way in TypeScript itself to test typings for pure JS projects, see

how about this?

// @ts-check

or this (that i have start doing):

{
  "include": ["*.js"],
  "compilerOptions": {
    "target": "ES2020",
    "lib": ["ES2020"],
    "module": "ES2020",
    "moduleResolution": "node",
    "allowJs": true,
    "checkJs": true,
    "declaration": true,
    "emitDeclarationOnly": true,
    "allowSyntheticDefaultImports": true,
    "skipLibCheck": true,
    "strictNullChecks": true
  }
}

I'm fine with type definitions doe - those can be generated out of jsdocs but shouldn't be needed

from just.

angus-c avatar angus-c commented on May 18, 2024

@jimmywarting I share many of your concerns about using Typescript syntax directly, but note they don't really apply here. There is no TypeScript in Just source code, just type definition files for consuming app to validate against.

from just.

angus-c avatar angus-c commented on May 18, 2024

Closing as we now have a documented strategy for this.

from just.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.