-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate to TypeScript? #376
Comments
I'm willing to help out if need be. |
FWIW, VS Code might be the only acceptable editor for typescript. I tried something small in Atom over the weekend, and it was very Rust, with the recommended add-on. No help, bustages on compile, unhelpful error messages. In VS Code, the experience was pretty different. But even then, there were warnings arount tslint that couldn't be fixed following the instructions. I'd assume that typescript comes with quite a vendor lock in. |
IntelliJ also works great for TS. Afaik lots of TS IDE functionality comes from its language server, so it should behave pretty similar between editors. |
I'd be happy if this project moves to TypeScript as well. I'm thankful the TypeScript definitions exist (and it is usable), but I feel it's not quite "there" yet and there might not be enough eyes looking at it to keep up with all the changes and edge cases. As for editors, Atom seems to have the |
Not wanting to derail this issue into an editor discussion, but I write a lot of TS in vim using tsuquyomi for TS support--and there are other vim/TS projects too like nvim-typescript. I rarely open VS Code so I don't think vendor lock-in should be a concern for switching to TS. |
I would say I've also had great experiences using typescript in my projects and not having type definitions for fluent actively hampers my ability to use it so either this or #329 would be a big help. I came to mention though that having proper types might end up changing some of the APIs so it isn't necessarily a backwards compatible change. The example I just hit is the |
Good points about the API changes in For now, I've started an experiment and ported I'm having troubles with tests, however. I transpile TS files to ES modules but our test runner, mocha, doesn't support ES modules yet. I'll look for solutions and also for alternatives (like Jest). |
@stasm Jest works very well with TypeScript and also gives you code coverage out of the box. I think you should give it a try. |
It does look like a very nice test runner indeed. Re. TypeScript, I think it supports it via transpiling input files with Babel, doesn't it? Which we could also do with mocha, I think, if needed. And since we would build ES code with |
I use it with |
My first thought was to only migrate |
You don't need |
Small note that I have encountered a library written in TypeScript with tests written mostly in JavaScript that produced incorrect type definitions. The code worked fine in JS land, but it produced a compilation failure in TS. The bug was in an interface definition, so it didn't affect the JavaScript code behavior. Since all the tests for that module was in JS, type definitions weren't covered, and it apparently went undetected for quite some time. With that said, the case seems to be fairly uncommon, and I agree that we probably wouldn't need to port all the tests to TypeScript. |
@Seally I'm not sure I follow your train of thoughts. Unless you make TS typecheck JS files (usually through |
@huy-nguyen I'm not saying JavaScript test code causes TypeScript compilation errors, but that having test code written exclusively in JS means that the type definitions aren't covered by tests. This could possibly allow type definition issues to slip through if no one happened to try to import and use the code in TypeScript. Although TS does help in avoiding a large class of bugs, and static typing is amazing for IDEs, it unfortunately also introduces a new class of bugs in its place. For the case in question, it didn't cause compilation errors when the library was built because the type error could only be triggered when code was referenced, not when it was defined. As it was part of the public API and no other part depended on it, it was not referenced elsewhere within the project from TypeScript code. The only code that referenced the exports in that project were the test cases, written in JS. They tested the runtime behavior of the code, which was correct. Since JS tests aren't type-checked, they did not test if it would compile when it was imported in TypeScript code and consumed. The exact issue involved JSX typings (the project in question is |
@Seally I see what you mean. I think running |
I believe the aforementioned issue will show up only if I actually use the component in another program, since it wasn't caught during build which did go through The problem in question, however, was a bit like this, rather horrible, example:
// This file compiles.
// ... required imports
export interface BadProps {
children?: VNode // In ComponentProps, this is defined as children?: InfernoNode
}
export class BadComponent extends Component { constructor(props: BadProps) { /* ... */ } } Imported: // ... some other imports to make this work
import { BadComponent } from "my-component"; // if we end the file here, this will still work.
render(<BadComponent>/* ... */</BadComponent>, /* root */); // type error In this case, there's no valid JSX input that can go into the This is admittedly a niche case of course, and it was caused partly because some of the typings weren't strict enough. With that said, I agree that TypeScript for test cases generally won't be needed. Additionally, JS test code can reach code paths that are usually restricted under TS. For tests dealing with potentially complicated typings (React hooks and Fluent resource bundle come to mind) however, it may be a good idea to write TS test cases with type-checking somewhere in the test pipeline just to be sure it won't cause issues when a TypeScript user imports and uses it. |
I submitted #436 with my proof-of-concept port of I'd like to thank everyone who has contributed to Fluent's typings in the |
I just merged #436 and published |
I'll keep this issue open to track progress of migrating the remaining |
As of today, all packages in this repository have been migrated to TypeScript, and for most of them, I published new releases to npm. Here's the full list:
Thanks to @Gregoor, @huy-nguyen, @Pike, @Seally, and @zbraniecki for the guidance, help and reviews! |
Over the last month I've used TypeScript in a side-project, and it's been a delight. It's quick to pick up, doesn't get into the way, has excellent editor support in VS Code, and compiles to readable JS. I'd like to kick off a discussion about migrating the
fluent.js
family of packages to TypeScript,. We could start with the more user-facing ones:fluent
,fluent-react
, andfluent-langneg
, which also have the benefit of being small, well tested, and of already having user-contributed typings thanks to @huy-nguyen.See also: #329, #231.
Update (January 2020)
The migration is currently ongoing. I'll keep the following list up to date as more packages are migrated.
@fluent/bundle
: Migrate @fluent/bundle to TypeScript #436, v0.15.0@fluent/dedent
: (@fluent/dedent) Migrate to TypeScript #451 v0.2.0@fluent/dom
: Build @fluent/dom with TypeScript #474@fluent/langneg
: Migrate @fluent/langneg to TypeScript #462 v0.4.0@fluent/react
: Migrate @fluent/react to TypeScript #458 v0.12.0@fluent/sequence
: Migrate @fluent/sequence to TypeScript #450 v0.5.0@fluent/syntax
: (@fluent/syntax) Migrate to TypeScript #457 v0.15.0The text was updated successfully, but these errors were encountered: