Yomguithereal / baobab

JavaScript & TypeScript persistent and optionally immutable data tree with cursors.
MIT License
3.15k stars 117 forks source link

Supporting TypeScript #464

Closed AlbertZheng closed 4 years ago

AlbertZheng commented 8 years ago

In order to support TypeScript, I changed below. Please review.

  1. Upgraded babel from 5.6.14 to the newest 6.6.4, so that the generated ES2015 codes by babel can compatibly work with codes generated by TypeScript compiler and webpack.
  2. Added the TypeScript Definitely Typed File index.d.ts.
  3. Added index.js for working in with index.d.ts
  4. Modified package.json correspondingly.

BTW, I fixed a bug in watcher.js which emitted a event without carrying the event object.

Yomguithereal commented 8 years ago

Hello @AlbertZheng. Thanks for you work! This seems like a nice and awaited enhancement. I want to merge your PR but it seems that when updating to Babel 6 you broke the test command requiring babel's register hook. Can you fix it so I can merge please?

If you don't know how, just tell me & I'll merge then fix the issue plus one another concerning ES6 exports and backward compatibility with CommonJS.

AlbertZheng commented 8 years ago

but it seems that when updating to Babel 6 you broke the test command requiring babel's register hook. Can you fix it so I can merge please?

If you don't know how, just tell me & I'll merge then fix the issue plus one another concerning ES6 exports and backward compatibility with CommonJS.

@Yomguithereal Sorry, I checked the CI errors, but I amn't familiar with babel hook. Could you please merge the PR then fix this issue? Thanks in advance.

AlbertZheng commented 8 years ago

Update the README.md for TypeScript usage.

@Yomguithereal I added a new commit for updating the README.md for TypeScript usage.

Yomguithereal commented 8 years ago

Thanks @AlbertZheng. I'll need to find some time to merge the PR and publish a release however. It should be done soon, don't worry.

Yomguithereal commented 8 years ago

Also, don't you need to indicate the typings in the package.json file?

AlbertZheng commented 8 years ago

Also, don't you need to indicate the typings in the package.json file?

It doesn't need the typings indication in the package.json of Baobab user's project, and also doesn't need an individual typings.json in user's project. Just npm install baobab like before, then the compiler of TypeScript will search the node_modules/baobab and find out the index.d.ts according to the indication of "main": "./index.js" in the package.json of Baobab package.

BTW, the typings has been deprecated by the newest TypeScript 2.x, instead using such as npm install @types/react which will install the TypeScript Definitely Typed File into node_modules/@types/react if this package doesn't distribute the official .d.ts files together with its npm publication.

Yomguithereal commented 7 years ago

Not forgetting you. Just trying to find someone knowledgeable in TypeScript to help me review the code.

AlbertZheng commented 7 years ago

@Yomguithereal I had added a section to describe the TypeScript usage in README.md of this PR commit.

The first step for using this TypeScript supporting PR is to use node module resolution option in the TypeScript compiler config file tsconfig.json of user's project, and most users are using this option.

  1. Checking the tsconfig.json of your TypeScript project, and make sure the compilerOptions is using node module resolution.
"compilerOptions": {
  ...
  "moduleResolution": "node",
  ...
}
luccitan commented 7 years ago

Hi,

I am not a TypeScript user, but I did some changes so that :

It is available in this commit. You can either update this PR or push one I create

Yomguithereal commented 4 years ago

Sorry everyone for lagging on this PR. But the upside is the lib now has type declaration (some years later) :)