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 typings for 'dojox/gfx' #43

Closed
wants to merge 16 commits into from
Closed

Add typings for 'dojox/gfx' #43

wants to merge 16 commits into from

Conversation

msssk
Copy link
Contributor

@msssk msssk commented Oct 10, 2016

This PR adds typings to make dojox/gfx usable with TypeScript.

It omits typings for all renderers, since those modules are not typically loaded directly. The API they implement is typed in the gfx.d.ts and gfx/shapes.d.ts files.

Also omitted:

  • _gfxBidiSupport: this module just modifies the base gfx module
  • attach: this module is empty
  • renderer: this module is an AMD loader plugin for loading the default renderer

Typings for two dojox dependencies outside of dojox/gfx are also included:

  • dojox/html/metrics
  • dojox/xml/DomParser

r: number;
}

// TODO: maybe complete this? (probably not important)
Copy link
Member

Choose a reason for hiding this comment

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

Can we update this comment to list what is missing and why we're leaving it off (e.g. renderers are mostly an internal construct). That way if somebody does need this they at least know why it's incomplete.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

y: number;
}

interface RadialFill {
Copy link
Member

Choose a reason for hiding this comment

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

Should this extend SimpleShape? I ask because RadialGradient does and both have optional type params.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This might in fact be useless code. It's hard to tell. It looks like this typedef is only applicable to dojox/gfx/gradutils.getColor, which AFAICT isn't even used anywhere in dojox.gfx. SimpleShape is a construct of my inventing, since there are also dojox.gfx.shape.Shape shapes. I think we can leave this as-is until/if someone finds that it would work better if it is changed.

}

interface MoverConstructor extends dojo._base.DeclareConstructor<Mover> {
new(shape: dojox.gfx.shape.Shape, event: MouseEvent, host: Moveable): Mover;
Copy link
Member

Choose a reason for hiding this comment

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

Does this file need a reference to shape or will TypeScript attempt to search for local .d.ts files?

/// <reference path="shape.d.ts" />

So if somebody used only this definition I believe they would get a missing definition error, but I'm not sure. Worth following up on.

Copy link
Contributor Author

@msssk msssk Oct 11, 2016

Choose a reason for hiding this comment

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

In my experience adding reference paths to .d.ts files causes namespace resolution to fail.

moveTo(x: number, y: number): this;
qCurveTo(x1: number, y1: number, x: number, y: number): this;
setAbsoluteMode(mode: boolean | string): void; // TODO: enum
// setShape(shape: string | dojox.gfx.path.Path): this;
Copy link
Member

Choose a reason for hiding this comment

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

Why is this commented out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It exists here because this is where I wish we could define it, but TS doesn't work like that. It also exists elsewhere, where we have to define it if we don't want to get errors.

const Path: dojox.gfx.path.PathConstructor;
type TextPath = dojox.gfx.path.TextPath;
const TextPath: dojox.gfx.path.TextPathConstructor;
/* tslint:enable */
Copy link
Member

Choose a reason for hiding this comment

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

Does this need an export statement?

Copy link
Contributor Author

@msssk msssk Oct 11, 2016

Choose a reason for hiding this comment

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

No - if you assign to export, then whatever you assign to export is all that gets exported - all the other statements have no effect.

y: number;
}

interface Container {
Copy link
Contributor

Choose a reason for hiding this comment

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

would it be ok to have the children property listed too?

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, thanks!

createImage(options: dojox.gfx.SimpleImage): Image;
createLine(options: dojox.gfx.SimpleLine): Line;
createObject(constructor: ShapeConstructor, simpleShape?: SimpleShape): Shape;
createPath(options: dojox.gfx.SimplePath): dojox.gfx.path.Path;
Copy link
Contributor

Choose a reason for hiding this comment

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

createPath() also accepts string like setShape

setShape(shape: dojox.gfx.SimpleShape): this;
// for Path
setShape(shape: string | dojox.gfx.path.Path): this;
// for Polyline
setShape(points: Point[] | { points: Point[] }, closed?: boolean): this;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks!


interface Stroke extends SimpleShape {
cap?: string; // TODO: enum
color?: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

color can be number[], string, dojo/_base/Color

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks!

@devpaul
Copy link
Member

devpaul commented Oct 15, 2016

merged in df21978

@devpaul devpaul closed this Oct 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants