nodejs-driver
nodejs-driver copied to clipboard
NODEJS-680: Update and Automate TypeScript Support
Massive refactoring. Changes can be broken down into the following parts:
- Rename files from
.jsto.ts. - Update import/export syntax to ESM syntax - some index files have to export both named and default to be compatible with the previous
requirebehavior. - Refactor ES5 style classes to ES6 style classes
- Cleaning TypeScript errors and eslint errors in
core - Fix API exposure - My rationale is: if an API was exposed in previous
.d.ts, it's supposed to be exposed. If it has documentation on how a user should use it, it's supposed to be exposed. There are some inconsistencies. Please search//TODOto find them. - Make sure tests pass and set up CI: Replace the use of proxyquire to sinon. Add rollup for bundle, api-extractor to encapusulate, and eslint for linting.
We need to discuss:
- Please search
//TODOto find the places where I am not sure what to do. Some are breaking changes. - How can we maintain backward compatibility of the dotted type names, like
cassandra.errors.DriverError? In the current master branch, this is the only way to use types:
import cassandra from 'cassandra-driver';
// ...
client.execute(query, (err: cassandra.errors.DriverError, result: cassandra.types.ResultSet) => {});
Or, with one level down imports
import {errors, types } from 'cassandra-driver';
client.execute(query, (err: errors.DriverError, result: types.ResultSet) => {});
However, the TypeScript default way, also the way how other libraries expose the types, is to flatten all exported classes.
import {DriverError, ResultSet } from 'cassandra-driver';
client.execute(query, (err: DriverError, result: ResultSet) => {});
Now how can we maintain backward compatibility to the previous dotted ones? The only workaround I can find is to append such things at the end of our dist/cassandra-driver-public.d.ts
export namespace errors{
export type DriverError = InstanceType<typeof DriverError>;
}
This is the last step of the bundle script in this PR.
3. How do we maintain backward compatibility of import x = y.z syntax?
import { mapping } from "../../../index";
import Mapper = mapping.Mapper;
const mapper: Mapper = new Mapper();
This currently will raise an error Mapper is a type, but used as a value. I cannot see a solution.
- What do we want to do with our documentation? Should we update all code snippets into TypeScript?
I forgot Travis CI. Will fix.
Contact doc team and see what we should do with JSdoc type definitions v.s. TypeScript type definitions.
Minimal reproducible case for import x = y.z error
Optimize the pipeline to only distribute necessary files.