Skip to content

Commit

Permalink
chore: use local TypeScript with dtslint (ReactiveX#4712)
Browse files Browse the repository at this point in the history
* chore: replace prepublish with prepublishOnly

* chore: use local typescript with dtslint

* chore: restore commented-out dtslint tests

* chore: replace prepublishOnly with prepublish
  • Loading branch information
cartant authored and BioPhoton committed May 15, 2019
1 parent 9164216 commit 7e8e4cc
Show file tree
Hide file tree
Showing 12 changed files with 910 additions and 296 deletions.
1,081 changes: 851 additions & 230 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"lint_spec": "tslint -c tslint.json \"spec/**/*.ts\"",
"lint_src": "tslint -c tslint.json \"src/**/*.ts\"",
"lint": "npm-run-all --parallel lint_*",
"dtslint": "npm run build_types && npx dtslint spec-dtslint",
"dtslint": "npm run build_types && node ./spec-dtslint/script.js",
"perf:protractor": "echo \"Protractor is not working currently\" && exit -1 && protractor protractor.conf.js",
"perf:micro": "node ./perf/micro/index.js",
"prepublish": "shx rm -rf ./typings && npm run build_all",
Expand Down Expand Up @@ -196,6 +196,7 @@
"danger": "1.1.0",
"dependency-cruiser": "2.13.0",
"doctoc": "1.3.0",
"dtslint": "0.6.1",
"escape-string-regexp": "1.0.5",
"esdoc": "0.4.7",
"eslint": "4.17.0",
Expand Down
7 changes: 3 additions & 4 deletions spec-dtslint/observables/combineLatest-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ it('should accept 6 params', () => {
const o = combineLatest(a, b, c, d, e, f); // $ExpectType Observable<[A, B, C, D, E, F]>
});

// TODO(benlesh): This test broken by TS next (> 3.4)... Observable<unknown> is returned.
// it('should result in Observable<{}> for 7 or more params', () => {
// const o = combineLatest(a, b, c, d, e, f, g); // $ExpectType Observable<{}>
// });
it('should result in Observable<{}> for 7 or more params', () => {
const o = combineLatest(a, b, c, d, e, f, g); // $ExpectType Observable<{}>
});

it('should accept union types', () => {
const u1: typeof a | typeof b = Math.random() > 0.5 ? a : b;
Expand Down
7 changes: 3 additions & 4 deletions spec-dtslint/observables/concat-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ it('should accept more than 6 params', () => {
const o = concat(of(1), of(2), of(3), of(4), of(5), of(6), of(7), of(8), of(9)); // $ExpectType Observable<number>
});

// TODO(benlesh): This test broken by TS next (> 3.4)... Observable<unknown> is returned.
// it('should return Observable<{}> for more than 6 different types of params', () => {
// const o = concat(of(1), of('a'), of(2), of(true), of(3), of([1, 2, 3]), of(4)); // $ExpectType Observable<{}>
// });
it('should return Observable<{}> for more than 6 different types of params', () => {
const o = concat(of(1), of('a'), of(2), of(true), of(3), of([1, 2, 3]), of(4)); // $ExpectType Observable<{}>
});

it('should accept scheduler after params', () => {
const o = concat(of(4), of(5), of(6), asyncScheduler); // $ExpectType Observable<number>
Expand Down
21 changes: 10 additions & 11 deletions spec-dtslint/observables/forkJoin-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,16 @@ it('should infer correctly with 6 parameters', () => {
const res = forkJoin(a, b, c, d, e, f); // $ExpectType Observable<[number, string, number, number, number, number]>
});

// TODO(benlesh): this needs to be fixed as well
// it('should infer of type any for more than 6 parameters', () => {
// const a = of(1, 2, 3);
// const b = of('a', 'b', 'c');
// const c = of(1, 2, 3);
// const d = of(1, 2, 3);
// const e = of(1, 2, 3);
// const f = of(1, 2, 3);
// const g = of(1, 2, 3);
// const res = forkJoin(a, b, c, d, e, f, g); // $ExpectType Observable<{}>
// });
it('should infer of type any for more than 6 parameters', () => {
const a = of(1, 2, 3);
const b = of('a', 'b', 'c');
const c = of(1, 2, 3);
const d = of(1, 2, 3);
const e = of(1, 2, 3);
const f = of(1, 2, 3);
const g = of(1, 2, 3);
const res = forkJoin(a, b, c, d, e, f, g); // $ExpectType Observable<any>
});

it('should infer correctly for array of 1 observable', () => {
const a = [of(1, 2, 3)];
Expand Down
25 changes: 11 additions & 14 deletions spec-dtslint/operators/pluck-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,17 @@ it('should support nested object of 6 layer depth', () => {
const a = of({ a: { b: { c: { d: { e: { name: 'abc' } } } } } }).pipe(pluck('a', 'b', 'c', 'd', 'e', 'name')); // $ExpectType Observable<string>
});

// TODO(benlesh): This test broken by TS next (> 3.4)... Observable<unknown> is returned.
// it('should support nested object of more than 6 layer depth', () => {
// const a = of({ a: { b: { c: { d: { e: { f: { name: 'abc' } } } } } } }).pipe(pluck('a', 'b', 'c', 'd', 'e', 'f', 'name')); // $ExpectType Observable<{}>
// });

// TODO(benlesh): This test broken by TS next (> 3.4)... Observable<unknown> is returned.
// it('should infer empty interface for non-existance key', () => {
// const a = of({ name: 'abc' }).pipe(pluck('xyz')); // $ExpectType Observable<{}>
// });

// TODO(benlesh): This test broken by TS next (> 3.4)... Observable<unknown> is returned.
// it('should infer empty interface for empty parameter', () => {
// const a = of({ name: 'abc' }).pipe(pluck()); // $ExpectType Observable<{}>
// });
it('should support nested object of more than 6 layer depth', () => {
const a = of({ a: { b: { c: { d: { e: { f: { name: 'abc' } } } } } } }).pipe(pluck('a', 'b', 'c', 'd', 'e', 'f', 'name')); // $ExpectType Observable<{}>
});

it('should infer empty interface for non-existance key', () => {
const a = of({ name: 'abc' }).pipe(pluck('xyz')); // $ExpectType Observable<{}>
});

it('should infer empty interface for empty parameter', () => {
const a = of({ name: 'abc' }).pipe(pluck()); // $ExpectType Observable<{}>
});

it('should accept string only', () => {
const a = of({ name: 'abc' }).pipe(pluck(1)); // $ExpectError
Expand Down
3 changes: 1 addition & 2 deletions spec-dtslint/operators/publish-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ it('should support empty parameter', () => {
// the next version infers Observable<number>. It's not possible to specify
// an upper bound for the TypeScript version used by dtslint, so an
// expectation cannot be applied.
// TODO: put the test back after Typescript > 3.2
const a = of(1, 2, 3).pipe(publish());
const a = of(1, 2, 3).pipe(publish()); // $ExpectType Observable<any>
});

it('should infer when type is specified', () => {
Expand Down
3 changes: 1 addition & 2 deletions spec-dtslint/operators/publishLast-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ it('should accept empty parameter', () => {
// the next version infers Observable<number>. It's not possible to specify
// an upper bound for the TypeScript version used by dtslint, so an
// expectation cannot be applied.
// TODO: put the test back after Typescript > 3.2
const a = of(1, 2, 3).pipe(publishLast());
const a = of(1, 2, 3).pipe(publishLast()); // $ExpectType Observable<any>
});

it('should infer when type is specified', () => {
Expand Down
21 changes: 10 additions & 11 deletions spec-dtslint/operators/withLatestFrom-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,16 @@ describe('withLatestFrom', () => {
const res = a.pipe(withLatestFrom(b, c, d, e, f)); // $ExpectType Observable<[number, string, string, string, string, string]>
});

// TODO(benlesh): This test broken by TS next (> 3.4)... Observable<unknown> is returned.
// it('should only accept maximum params of 5', () => {
// const a = of(1, 2, 3);
// const b = of('a', 'b', 'c');
// const c = of('d', 'e', 'f');
// const d = of('g', 'h', 'i');
// const e = of('j', 'k', 'l');
// const f = of('m', 'n', 'o');
// const g = of('p', 'q', 'r');
// const res = a.pipe(withLatestFrom(b, c, d, e, f, g)); // $ExpectType Observable<{}>
// });
it('should only accept maximum params of 5', () => {
const a = of(1, 2, 3);
const b = of('a', 'b', 'c');
const c = of('d', 'e', 'f');
const d = of('g', 'h', 'i');
const e = of('j', 'k', 'l');
const f = of('m', 'n', 'o');
const g = of('p', 'q', 'r');
const res = a.pipe(withLatestFrom(b, c, d, e, f, g)); // $ExpectType Observable<{}>
});
});

describe('with project parameter', () => {
Expand Down
11 changes: 5 additions & 6 deletions spec-dtslint/operators/zip-spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Observable, of } from 'rxjs';
import { zip } from 'rxjs/operators';

// TODO(benlesh): This test broken by TS next (> 3.4)... Observable<unknown> is returned.
// it('should support rest parameter observables', () => {
// const o = of(1); // $ExpectType Observable<number>
// const z = [of(2)]; // $ExpectType Observable<number>[]
// const a = o.pipe(zip(...z)); // $ExpectType Observable<{}>
// });
it('should support rest parameter observables', () => {
const o = of(1); // $ExpectType Observable<number>
const z = [of(2)]; // $ExpectType Observable<number>[]
const a = o.pipe(zip(...z)); // $ExpectType Observable<{}>
});

it('should support rest parameter observables with type parameters', () => {
const o = of(1); // $ExpectType Observable<number>
Expand Down
4 changes: 4 additions & 0 deletions spec-dtslint/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const { execSync } = require('child_process');
const path = require('path');
const local = path.resolve('./node_modules/typescript/lib');
execSync(`dtslint --localTs ${local} --expectOnly ./spec-dtslint`);
20 changes: 9 additions & 11 deletions spec-dtslint/util/pipe-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ function a<I extends string, O extends string>(input: I, output: O): UnaryFuncti
return i => output;
}

// TODO(benlesh): This test broken by TS next (> 3.4)... Observable<unknown> is returned.
// it('should infer {} for no arguments', () => {
// const o = pipe(); // $ExpectType UnaryFunction<{}, {}>
// });
it('should infer {} for no arguments', () => {
const o = pipe(); // $ExpectType UnaryFunction<{}, {}>
});

it('should infer for 1 argument', () => {
const o = pipe(a('0', '1')); // $ExpectType UnaryFunction<"0", "1">
Expand Down Expand Up @@ -116,14 +115,13 @@ it('should return an explicit Observable type', () => {
const o = of('foo').pipe(staticPipe); // $ExpectType Observable<string>
});

// TODO(benlesh): This test broken by TS next (> 3.4)... Observable<unknown> is returned.
// it('should return Observable<{}> when T cannot be inferred', () => {
// const customOperator = <T>() => (a: Observable<T>) => a;
it('should return Observable<{}> when T cannot be inferred', () => {
const customOperator = <T>() => (a: Observable<T>) => a;

// // type can't be possibly be inferred here, so it's {} instead of T.
// const staticPipe = pipe(customOperator());
// const o = of('foo').pipe(staticPipe); // $ExpectType Observable<{}>
// });
// type can't be possibly be inferred here, so it's {} instead of T.
const staticPipe = pipe(customOperator());
const o = of('foo').pipe(staticPipe); // $ExpectType Observable<{}>
});

it('should return a non-narrowed type', () => {
const func = pipe((value: string) => value, (value: string) => value + value);
Expand Down

0 comments on commit 7e8e4cc

Please sign in to comment.