Comments (13)
Discussion copied from #31:
Sorry for the delayed response @smalluban.
After a bit of consideration, here are my thoughts:
- Authoring hybrids modules in Flow or TypeScript is ideal because it would
- embed type safety into the library.
- eliminate what would otherwise be a bit of guesswork by type definition authors other than you, given your complete mental model of how this library works.
- possibly result in better / more specific typings.
- possibly prompt minor design changes that allow for more expressive types.
- Regarding the point of not having to transpile the code one day:
- I certainly acknowledge that this is likely to perform better and reduce bandwidth.
- However, I think it is going to be a while before this is no longer necessary. Many of my clients are still using IE11--yuck!
- The typical Flow setup simply involves a Babel plugin that only strips away the type annotations before other plugins take care of transpiling the code to ES5, etc. TypeScript appears to have a
--target
option that allows specific ES* versions to be targeted as well (see docs).
- If you have other reasons that the type definitions need to be separated from implementation, then the challenge of keeping them synchronized exists regardless of where they live. However, the flow-typed library has project structure and naming conventions for properly defining library version compatibility; and I assume the TypeScript analog has some way of addressing this problem as well.
TL;DR: My opinion (which is just an opinion, of course) is that writing the library in Flow or TypeScript is the best option; but, if the type definitions are to be separated, then we might as well follow the conventions that have been developed by the broader JS community.
On a side note, flow-to-typescript and flowgen look like interesting options for providing both options without having to define all the types twice. :-)
Anyway, thanks for the consideration, and I'm definitely interested in hearing more of your thoughts.
from hybrids.
@coedder I read your comment a few times, but I can't understand your point. This issue is about adding typings, that would help using the library with TypeScript ecosystem. Rewriting the library with TS is not required.
I would like to start with comments above exported functions in JSDoc or another tool standard. However, now I am focused on other stuff related to the library, so it has to wait.
from hybrids.
Good point. I planned to add typings from the beginning. Only it wasn't on top of my todo list. For now, I am finishing some new features, and then I take care of that. I should be done in the next month.
However, if you want to help with that, it also would be cool :)
from hybrids.
I think there is a way to still have untouched source code and typings inside of the repository. I looked at the redux:
- Source code is JavaScript
- Exports have comments with parameters documentation
- Package.json has
typings
field pointing toindex.d.ts
- All index typings are defined in
index.d.ts
file
I would recommend the same way here. I will add point 2 to my todo list. I am not familiar with defining typings, so creating index.d.ts
is an open case.
from hybrids.
Just chiming in here, I am willing to help write the typescript typings if / when you get around to commenting the exports with parameter documentation. I see you have a few in the docs already, so Iβll try my best to help out with that. This looks like a really cool library, I am a big proponent of types though so I canβt use it until it has typescript support.
from hybrids.
I think classes try to do something than JavaScript don't need to do, and if we use hybrids is because we can use web components in "the JavaScript way": plain objects and pure functions.
I think strict types are the same as classes for JavaScript: try to do something than JavaScript don't need to do.
JavaScript (almost always) run in a browser (a JavaScript engine), and if you write 1 + 1
you don't ask yourself. Could the browser run this code? Not the case when you write for a machine (hardware), here you need know what can and can not do that machine, and in this case is where strict types fit perfect. For example: Here is the list of the different numeric types in Rust: i8, i16, i32, i64, u8, u16, u32, u64, isize, usize, f32, f64. Which one I need to use? Depend most of the time of the machine where the code will run; Machines have strict limits, so my code should be strict (typed) too.
Diodes? Transistors? Integrated circuits? Optoelectronic devices? Power sources? Resistors? Capacitors? Inductive devices? This are thing I don't care when I write code in JavaScript.
Classes in JavaScript? Why? Are not needed, the same for explicit types.
from hybrids.
@smalluban TypeScript with JSDoc enables smoothly intellisense in VS Code π―
from hybrids.
Hi, I was wondering if there's been any progress on this? I am just starting to explore hybrids and it looks very cool, but a d.ts file with just typings would be super helpful, even without comments.
[Edit] Attempting to use hybrids in Typescript with VSCode, fyi.
from hybrids.
I will try to make some basic typings this week, I will update you when it will be done ;)
from hybrids.
@nsaunders @g5becks @coedder @xdvarpunen Ok, it took me a little more time, but here it is #80. It would be great if someone from you would like to do a review ;) I am not a heavy user of TS, so maybe some of the things could be written more in TS way (usage of type vs interface, naming conventions, etc.).
from hybrids.
I decided to merge #80. It was released with v4.1.0
, and with minor fixes, in v4.1.1
I think basic TypeScript support is done.
For now, I am closing this issue. However, anyone who wants better support is welcome to comment here with suggestions about how to make it better. If applicable I will re-open the issue.
from hybrids.
not sure if the issue needs to be reopened but when following the general typescript recommendations for hybrids, I get errors on the Component definition when the interface is already defined above.
i can disable the error with this
// eslint-disable-line @typescript-eslint/no-redeclare
but i wonder if there is another way to not litter all my component files with those ts exceptions
from hybrids.
It looks that it is specifically the eslint rule, not the TS itself. Usually, when I use TS, I skip the eslint (as it adds marginal benefits). You can see here on the TS playground that it does not complain about declaration variable with the same name as an interface.
It is not only a shortcut, but if you export that variable, the TS maps to it its interface, and where the interface should be used (for example in another interface) you can just use that interchangeably.
from hybrids.
Related Issues (20)
- Add a helper for assigning component properties HOT 3
- Dynamic columns not showing when render a html table HOT 4
- '"hybrids"' has no exported member named 'property'. Did you mean 'Property'? HOT 8
- Add support for "TypeScript v5" HOT 3
- I can't create an arbitrary number of nested forms: HOT 6
- Small Type Inferencing Issue with Property<E, V> HOT 6
- Cannot pass an object to the API via the "list" method HOT 7
- version 8.2.17 backwards compatibility is broken! HOT 9
- Expand the functionality of drafts
- sync() with nested models is broken HOT 4
- Allow storing an object in a component property HOT 4
- Add partial loading of model data HOT 3
- Why do you remove the lastValue? HOT 2
- The store logs a lot of errors HOT 4
- Convert a Whole Component to Web Component HOT 8
- Scoped CSS HOT 6
- lagging update glitch HOT 2
- Component properties cannot be setted until they are observed HOT 2
- `store.set()` is very slow HOT 5
- Store loads items data when iterating the list of items HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hybrids.