question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to handle types

See original GitHub issue

When documenting a field of a custom element, we definitely want to describe it’s type. Before TypeScript came along we almost would have certainly would have use JSDoc-style type annotation syntax, but TypeScript’s type syntax might be more commonly known by now though.

So we could use that in the descriptor, for example:

{
  "members": {
    "foo": {
      "kind": "property",
      "type": "Array<number|string>"
    }
  }
}

But at the limit you need to support many TS-specific, non-concrete entries like interfaces and type aliases so that you can use them in types. Does this mean we should leave types completely out of the format and up to .d.ts files? That would degrade the usefulness for documentation tools that don’t process type declaration files. TS declaration files are also harder to parse than JSON, requiring the whole TypeScript compiler.

Another option is to include much of the type-related information parsed by Microsoft’s API Extractor: https://github.com/microsoft/rushstack/tree/master/apps/api-extractor

Since this tool produces JSON, it would be relatively easy for custom-elements.json generators to use it to parse TypeScript, then merge with it’s own custom element specific parsed metadata.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
daKmoRcommented, Oct 28, 2019

For documentation purposes, it would be good enough to keep types more as “type hints”. e.g. to give an idea of what it should be… it does not need to be a “real” type.

Examples:

  • String (e.g. foo, bar, …)
  • Number (e.g. 1, 4342, …)
  • Color (e.g. #fff, orange, rgb(255,0,0), …)
  • Css Length (e.g. 10px, 10rem, …
  • Array (does NOT type content)
  • Object (does NOT type content)

REAL type support I would consider out of scope and should be handled separately by searching for *.d.ts files.

So many tools will be fine with only custome-elements.json. e.g. documentation, playgrounds, catalog, …

Some tools will need to “gather” more data to also give type safety. e.g. linters, editor plugins, …

1reaction
thepasslecommented, Dec 16, 2020

What about making a type declaration type,

I’d really prefer to stay as far from this as possible and avoid becoming an alternative/substitute for type declaration files.

iirc, if useSubscription is a function, that means the CEM should already list its return type, right? Function params/return types are supported by the current schema?

Read more comments on GitHub >

github_iconTop Results From Across the Web

5 Types of Handles and What They're Used For | Reid Supply
Pull handles; Twist handles; Lever handles; Door handles; Window handles ...
Read more >
How can I handle the different types in typescript?
You need to have kind property for both circle and square. Below should work. type Shape = | { kind: "circle"; radius: number...
Read more >
Data types: handle - Embedded Wizard
From Chora's point of view, handle operands are abstract data entity with not exactly specified content. Accordingly, you can store and compare references, ......
Read more >
Windows Programming/Handles and Data Types - Wikibooks
Windows Programming/Handles and Data Types · 1 Hungarian Notation · 2 LPVOID · 3 DWORD, WORD, BYTE · 4 LONG, INT, SHORT, CHAR...
Read more >
Your Basic Guide to Different Handle Types and a List of ...
As you can see, there a lot of different handles and a lot of various applications for different types. Finding the right handle...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found