Skip to content

Commit ef40a46

Browse files
types: enable use of strict in tsconfig (clientIO#2051)
1 parent 02ac92c commit ef40a46

File tree

5 files changed

+51
-21
lines changed

5 files changed

+51
-21
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ node_modules/
33
coverage/
44
*.log
55
demo/**/dist/**
6-
/test/ts/*.js*
6+
/test/ts/*.js
7+
/test/ts/*.js.map
78
.tscache/
89
.DS_Store

grunt/config/ts.js

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
module.exports = {
22
test: {
3-
src: ['test/ts/*.ts'],
4-
options: {
5-
noImplicitAny: true,
6-
forceConsistentCasingInFileNames: true,
7-
noImplicitReturns: true,
8-
noImplicitThis: true,
9-
strictNullChecks: false,
10-
suppressImplicitAnyIndexErrors: true,
11-
noUnusedLocals: false
3+
tsconfig: {
4+
tsconfig: 'test/ts/tsconfig.json',
5+
passThrough: true
126
}
137
}
148
};

test/ts/index.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ graph.addCell({
8484
});
8585

8686
// `cells` attribute is a collection of cells
87-
const cell = graph.get('cells').at(0);
87+
const cell = graph.get('cells')?.at(0);
8888
(<joint.dia.Element>cell).getBBox({ rotate: true }).inflate(5);
8989

9090
// ModelSetOptions
@@ -94,15 +94,15 @@ rectangle.set('test', true, { silent: true, customOption: true });
9494
// a child inherits attributes from `dia.Element`
9595
const cylinder = new joint.shapes.standard.Cylinder({ z: 0 });
9696
cylinder.set({ position: { x: 4, y: 5 }});
97-
cylinder.set('z', cylinder.attributes.z + 1);
97+
cylinder.set('z', (cylinder.attributes.z || 0) + 1);
9898

9999
const paper = new joint.dia.Paper({
100100
model: graph,
101101
frozen: true,
102102
findParentBy: (_elementView, _evt, x, y) => graph.findModelsFromPoint({ x, y })
103103
});
104104

105-
const cellView = cell.findView(paper);
105+
const cellView = graph.getCells[0].findView(paper);
106106
cellView.vel.addClass('test-class');
107107

108108
let isHTMLView: AssertExtends<typeof paper.vel, null> = true;

test/ts/tsconfig.json

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"include": [
3+
"**/*.ts",
4+
],
5+
"compilerOptions": {
6+
"target": "es6",
7+
"moduleResolution": "node",
8+
"pretty": true,
9+
"sourceMap": true,
10+
// The following options are enabled when using 'strict: true'
11+
"alwaysStrict": true,
12+
"noImplicitAny": true,
13+
"noImplicitThis": true,
14+
/*
15+
Rule is disabled due to design limitation with overloads in TypeScript
16+
https://github.com/microsoft/TypeScript/issues/38353
17+
https://github.com/microsoft/TypeScript/issues/42196
18+
*/
19+
"strictBindCallApply": false,
20+
"strictFunctionTypes": true,
21+
"strictNullChecks": true,
22+
"strictPropertyInitialization": true,
23+
"useUnknownInCatchVariables": true,
24+
// 'strict' options **End**
25+
"forceConsistentCasingInFileNames": true,
26+
"noImplicitReturns": true,
27+
"suppressImplicitAnyIndexErrors": true,
28+
"noUnusedLocals": false,
29+
"skipLibCheck": false,
30+
"types": [],
31+
}
32+
}

types/joint.d.ts

+11-8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export namespace dia {
1212

1313
type Event = JQuery.TriggeredEvent;
1414

15+
type ObjectHash = { [key: string]: any };
16+
1517
type Point = g.PlainPoint;
1618

1719
type BBox = g.PlainRect;
@@ -157,7 +159,7 @@ export namespace dia {
157159
}
158160
}
159161

160-
class Graph<A = Graph.Attributes, S = dia.ModelSetOptions> extends Backbone.Model<A, S> {
162+
class Graph<A extends ObjectHash = Graph.Attributes, S = dia.ModelSetOptions> extends Backbone.Model<A, S> {
161163

162164
constructor(attributes?: Graph.Attributes, opt?: { cellNamespace?: any, cellModel?: typeof Cell });
163165

@@ -314,7 +316,7 @@ export namespace dia {
314316
}
315317
}
316318

317-
class Cell<A = Cell.Attributes, S = dia.ModelSetOptions> extends Backbone.Model<A, S> {
319+
class Cell<A extends ObjectHash = Cell.Attributes, S extends Backbone.ModelSetOptions = dia.ModelSetOptions> extends Backbone.Model<A, S> {
318320

319321
constructor(attributes?: A, opt?: Graph.Options);
320322

@@ -485,7 +487,7 @@ export namespace dia {
485487
}
486488
}
487489

488-
class Element<A = Element.Attributes, S = dia.ModelSetOptions> extends Cell<A, S> {
490+
class Element<A extends ObjectHash = Element.Attributes, S extends Backbone.ModelSetOptions = dia.ModelSetOptions> extends Cell<A, S> {
489491

490492
isElement(): boolean;
491493

@@ -608,7 +610,7 @@ export namespace dia {
608610
}
609611
}
610612

611-
class Link<A = Link.Attributes, S = dia.ModelSetOptions> extends Cell<A, S> {
613+
class Link<A extends ObjectHash = Link.Attributes, S extends Backbone.ModelSetOptions = dia.ModelSetOptions> extends Cell<A, S> {
612614

613615
toolMarkup: string;
614616
doubleToolMarkup?: string;
@@ -1816,7 +1818,7 @@ export namespace dia {
18161818
}
18171819
}
18181820

1819-
class HighlighterView<Options = HighlighterView.Options> extends mvc.View<undefined, SVGElement> {
1821+
class HighlighterView<Options extends mvc.ViewOptions<undefined, SVGElement> = HighlighterView.Options> extends mvc.View<undefined, SVGElement> {
18201822

18211823
constructor(options?: Options);
18221824

@@ -2015,7 +2017,7 @@ export namespace highlighters {
20152017
}
20162018
}
20172019

2018-
class list<Item = any, Options = list.Options> extends dia.HighlighterView<Options> {
2020+
class list<Item = any, Options extends mvc.ViewOptions<undefined, SVGElement> = list.Options> extends dia.HighlighterView<Options> {
20192021

20202022
options: Options;
20212023

@@ -2189,7 +2191,7 @@ export namespace shapes {
21892191

21902192
type CylinderAttributes = dia.Element.GenericAttributes<CylinderSelectors>;
21912193

2192-
class Cylinder<S = dia.ModelSetOptions> extends dia.Element<CylinderAttributes, S> {
2194+
class Cylinder<S extends Backbone.ModelSetOptions = dia.ModelSetOptions> extends dia.Element<CylinderAttributes, S> {
21932195
topRy(): string | number;
21942196
topRy(t: string | number, opt?: S): this;
21952197
}
@@ -3300,6 +3302,7 @@ export namespace mvc {
33003302

33013303
interface ViewOptions<T extends (Backbone.Model | undefined), E extends Element = HTMLElement> extends Backbone.ViewOptions<T, E> {
33023304
theme?: string;
3305+
[key: string]: any;
33033306
}
33043307

33053308
interface viewEventData {
@@ -4136,7 +4139,7 @@ export namespace elementTools {
41364139
}
41374140
}
41384141

4139-
abstract class Control<T = Control.Options> extends dia.ToolView {
4142+
abstract class Control<T extends mvc.ViewOptions<undefined, SVGElement> = Control.Options> extends dia.ToolView {
41404143
options: T;
41414144
constructor(opt?: T);
41424145

0 commit comments

Comments
 (0)