dart-lang / dart-lang/language

Typings is a package that transpiles TypeScript to Dart and enable directly use of NPM packages. Lets make it sound

Open
#2,995 5 comments 1 reaction 0 assignees View on GitHub
Dominant language
TeX
Stars
2.9k
Forks
239
Avg merge
2d 18h
Merged PRs (30d)
14

Description

Hi,

I am the author of [js_bindings](https://pub.dev/packages/js_bindings) and now I've published [Typings](https://pub.dev/packages/typings).

The package transpiles a TypeScript declaration file (`.d.ts`) to Dart JS interop.
It will replace `js_bindings` as it has full [ES2023 interop](https://pub.dev/documentation/typings/latest/typings.core/typings.core-library.html).

The transpilling process can be done automatically to any NPM package that has a TS declaration file and also exposes a helper function that injects the JS into the DOM.
It basically allows a developer to use NPM packages without the burden of manually generate the JS interop nor having to add the script tag in the HTML file.

The builder tries to understand the TS code in an attempt to transpile sound Dart code.
However, this is no simple task.

Some questions:
- Can inline classes help here?
- How to make js types like `Array` or `[Symbol.iterator]` loopable?
- What types can be directly translated to Dart? You can check the current mappings [here](https://github.com/jodinathan/typings/blob/main/ts2dart/lib/src/ast/types/static.dart).
- What to do with types that doesn't exist as feature in Dart? Like unions, intersections, type guards (predicates) etc.
- Can Records be used for TS interfaces (anonymous classes)? They seem to be the best fit
- What to do with overloading methods?

I already currently address some of these questions and you can know more in the [README](https://github.com/jodinathan/typings/tree/main/typings) and the [WIP Wiki](https://github.com/jodinathan/typings/wiki/TypeScript-to-Dart).

As it is a new package and intended to use full Dart 3, we can make tests to find the best way to transpile the code before releasing an stable version.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.