Giter Site home page Giter Site logo

Comments (9)

thepassle avatar thepassle commented on June 22, 2024

For all intents and purposes this would just be:

"parameters": [
  {
    "name": "keys",
    "type": {
      "text": "(keyof this)[]"
    }
  }
]

Right?

from custom-elements-manifest.

bennypowers avatar bennypowers commented on June 22, 2024
this.notify(['a','b','c']);
this.notify(...['a','b','c']);
this.notify('a','b','c');

they're spec'd out as different things, if i'm reading it right:

https://tc39.es/ecma262/#sec-parameter-lists

from custom-elements-manifest.

thepassle avatar thepassle commented on June 22, 2024

But these would all be internally handled as being an array, right? No matter how the method is called (or how its specced), the method expects the argument to be an array. Im not sure what value we could add here

from custom-elements-manifest.

bennypowers avatar bennypowers commented on June 22, 2024

it's an array in the function body, but a spread at the call site

so, if the user followed the documentation as you defined it, they would

this.notify(['a','b','c']);

but that would break because keys.map(x => [x, this[x]] would evaluate to

[
  [
    ['a','b','c'],
    /* not something you'd usually index `this` with*/
    this[['a','b','c']]
  ]
]

instead of the intended:

[
  ['a', this.a],
  ['b', this.b],
  ['c', this.c]
]

from custom-elements-manifest.

thepassle avatar thepassle commented on June 22, 2024

this.notify(['a','b','c']);

Thats a fair point. How would this look like in the schema, though?

Maybe:

"parameters": [
  {
    "name": "keys",
    "spread": true,
    "type": {
      "text": "(keyof this)[]"
    }
  }
]

?

from custom-elements-manifest.

bennypowers avatar bennypowers commented on June 22, 2024

off the top

notify(a, ...keys, b) {}
"parameters": [
  { "name": "a" },
  {
    "name": "keys",
    "rest": true
  }, 
  { "name": "b" }
]

from custom-elements-manifest.

bennypowers avatar bennypowers commented on June 22, 2024

yeah, 🚲

from custom-elements-manifest.

bennypowers avatar bennypowers commented on June 22, 2024

i'd usually reach for an enum rather than a spread, maybe

"kind": "rest"
declare module 'schema' {
  export type Parameter {
    kind?: "rest"|"spread"
  }
}

from custom-elements-manifest.

justinfagnani avatar justinfagnani commented on June 22, 2024

We should do this, but I think a simple boolean like rest?: true would probably suffice. There's no other value on the single vs rest axis to represent. spread isn't a kind of parameter, it's an operation you can use for arguments, but we don't document calls/arguments. rest?: true goes alone with optional?: true that we have now.

from custom-elements-manifest.

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.