Skip to content
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

Add (incomplete) Typescript definitions #134

Merged
merged 7 commits into from
Nov 18, 2017
Merged

Add (incomplete) Typescript definitions #134

merged 7 commits into from
Nov 18, 2017

Conversation

andrew8er
Copy link
Contributor

These are probably wrong and/or incomplete. They may serve as a starter though.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 0f38d10 on andrew8er:feature/typescript-definitions into ** on mtth:master**.

@andrew8er andrew8er mentioned this pull request Nov 6, 2017
Copy link
Owner

@mtth mtth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is super cool, thank you for the PR! Mostly nits and a few questions.

types/index.d.ts Outdated
export type CodecTransformer = (buffer: Buffer, callback: () => void) => Buffer; // TODO

export interface CodecOptions {
deflate: CodecTransformer;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 8 spaces per tab a strong convention for typings? If not, can we switch to 2 for consistency with the other files?

Copy link
Contributor Author

@andrew8er andrew8er Nov 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no strong feelings on file indentations, although I think that two spaces do not provide enough visual contrast.

types/index.d.ts Outdated

export type Callback<V, Err = any> = (err: Err, value: V) => void;

export type CodecTransformer = (buffer: Buffer, callback: () => void) => Buffer; // TODO
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd probably be easier to extend if we omit partial types entirely. Can you remove this and all other non-complete types in the file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CodecTransformer definition is almost correct, as far as I can see it, only the callback definition might be lacking an argument. I think, the definition has a certain value, because programmers will provide those functions and thus can be sure they are defined correctly.

types/index.d.ts Outdated
}

export interface Decoder {
on(type: 'metadata', callback: (type: Type.Type) => void): this;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that TypeScript is able to support different callback types for different events?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it does!

types/index.d.ts Outdated
export function parse(schemaOrProtocolIdl: string, options?: any): Service.Protocol | Type.Type; // TODO
export function readProtocol(protocolIdl: string, options?: ReaderOptions): Service.Protocol;
export function readSchema(schemaIdl: string, options?: ReaderOptions): Type.Schema;
// TODO streams
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless you're certain that they are exhaustive, can we remove the commented TODOs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am actually not sure if these are exhaustive, hence the TODO…

types/index.d.ts Outdated

interface ClientOptions {
buffering: boolean;
cache: any;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cache option is deprecated, can we remove it?

types/index.d.ts Outdated
createServer(options?: ServerOptions): Server;
message(name: string): any;
type(name: string): any;
inspect(name: string): any;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it's useful to include this method, it's an override just for pretty-printing in the REPL.

types/index.d.ts Outdated
}

function compatible(client: Client, server: Server): boolean;
function forProtocol(protocol: Protocol): Service;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be too restrictive. It's sometimes useful to instantiate services from inlined JavaScript objects, which I think this would prevent, right?

types/index.d.ts Outdated
// TODO types

export namespace Type {
type Schema = string;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Schemas can also be JavaScript objects (for example {type: 'map', values: 'int'}).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Js object could also be completely typechecked. Have a look at https://github.com/joewood/avro-typescript/blob/master/src/model.ts

Maybe we could extract a common Ts definition for Avro schemas for use in booth projects.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling be9936c on andrew8er:feature/typescript-definitions into ** on mtth:master**.

@mtth mtth merged commit be9936c into mtth:master Nov 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants