Skip to content

Commit

Permalink
TypeScript 3.6.4 (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
hchauvin authored Oct 14, 2019
1 parent 631e8ba commit 14f0cf6
Show file tree
Hide file tree
Showing 19 changed files with 1,157 additions and 635 deletions.
9 changes: 8 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2.1
defaults: &defaults
working_directory: ~/repo
docker:
- image: circleci/node:10.16.3-browsers
- image: circleci/node:latest-browsers

commands:
test:
Expand All @@ -21,6 +21,12 @@ commands:
- run: yarn all

jobs:
test_3_5_1:
<<: *defaults
steps:
- test:
typescript_version: "3.5.1"

test_3_4_1:
<<: *defaults
steps:
Expand All @@ -39,4 +45,5 @@ workflows:
test-deploy:
jobs:
- test_3_4_1
- test_3_5_1
- test
9 changes: 6 additions & 3 deletions packages/example_fast_check/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
"scripts": {
"ts": "ttsc -p tsconfig.json",
"start": "node build/index.js",
"test": "ava build/**/*.{test,it}.js",
"test": "ava",
"all": "yarn ts && yarn test"
},
"ava": {
"files": ["build/**/*.{test,it}.js"]
},
"devDependencies": {
"ava": "^1.4.1",
"typescript": "3.5.1"
"ava": "^2.4.0",
"typescript": "3.6.4"
},
"sideEffects": false,
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion packages/example_rpc_ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"ttypescript": "^1.5.7"
},
"devDependencies": {
"typescript": "3.5.1"
"typescript": "3.6.4"
},
"scripts": {
"ts": "ttsc -p tsconfig.json",
Expand Down
2 changes: 1 addition & 1 deletion packages/example_safe_json_parse/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"ttypescript": "^1.5.7"
},
"devDependencies": {
"typescript": "3.5.1"
"typescript": "3.6.4"
},
"scripts": {
"ts": "ttsc -p tsconfig.json",
Expand Down
15 changes: 9 additions & 6 deletions packages/example_webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
"ttypescript": "^1.5.7"
},
"devDependencies": {
"@babel/polyfill": "^7.0.0",
"@babel/polyfill": "^7.6.0",
"@types/lodash": "^4.14.106",
"@types/mocha": "^2.2.41",
"@types/node": "^8.0.47",
"@types/node": "^12.7.12",
"@types/path-is-inside": "^1.0.0",
"@types/puppeteer": "^1.5.1",
"@types/query-string": "^5.1.0",
Expand All @@ -28,10 +28,10 @@
"@types/terser-webpack-plugin": "^1.2.1",
"@types/uuid": "^3.4.4",
"@types/webpack-dev-server": "^3.1.1",
"ava": "^1.4.1",
"ava": "^2.4.0",
"cross-env": "^5.2.0",
"css-loader": "^0.28.11",
"node-sass": "^4.9.0",
"node-sass": "^4.12.0",
"postcss-loader": "^2.1.4",
"prettier": "^1.13.7",
"sass-loader": "^7.0.3",
Expand All @@ -43,7 +43,7 @@
"tslint-config-standard": "^7.0.0",
"tslint-language-service": "^0.9.8",
"tslint-no-circular-imports": "^0.6.1",
"typescript": "3.5.1",
"typescript": "3.6.4",
"url-loader": "^1.0.1",
"webpack": "^4.4.1",
"webpack-cli": "^3.1.0",
Expand All @@ -54,13 +54,16 @@
"lint": "tslint -p tsconfig.json",
"format": "prettier --write --ignore-path .gitignore '**/*.ts'",
"format:check": "prettier -l --list-different --ignore-path .gitignore '**/*.ts'",
"test": "ava build/**/__tests__/*.{test,it}.js",
"test": "ava",
"all": "yarn format:check && yarn lint && yarn ts && yarn test",
"precommit": "lint-staged",
"web": "webpack-dev-server --config webpack.config",
"doc": "echo 'SKIPPED'",
"heroku-postbuild": "yarn web:build"
},
"ava": {
"files": ["build/**/__tests__/*.{test,it}.js"]
},
"lint-staged": {
"{./*,typescript/**/*}.{js,jsx,ts,tsx,css,scss,md,json}": "prettier -l",
"*.{ts,tsx}": "tslint -c tslint.json"
Expand Down
17 changes: 11 additions & 6 deletions packages/reify_ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
"@types/benchmark": "^1.0.31",
"@types/fs-extra": "^5.0.5",
"@types/lodash": "^4.14.106",
"@types/node": "^8.0.47",
"@types/react": "^16.8.10",
"@types/node": "^12.7.12",
"@types/react": "^16.9.5",
"@types/rimraf": "^2.0.2",
"@types/sinon": "^2.3.7",
"antd": "^3.15.2",
"ava": "^1.4.1",
"ava": "^2.4.0",
"benchmark": "^2.1.4",
"coveralls": "^3.0.2",
"fast-check": "^1.5.0",
Expand All @@ -50,15 +50,17 @@
"typedoc": "^0.14.2",
"typedoc-plugin-external-module-name": "^2.0.0",
"typelevel-ts": "^0.3.5",
"vue": "^2.6.10"
"vue": "^2.6.10",
"source-map": "^0.7.3",
"source-map-support": "^0.5.13"
},
"peerDependencies": {
"typescript": ">= 3.4.1"
},
"scripts": {
"clean": "rimraf lib dist es typedoc",
"test": "ava 'lib/**/__tests__/*.{test,it}.js' --verbose --concurrency=20",
"cov": "yarn nyc --reporter=html --reporter=text ava 'lib/**/__tests__/*.{test,it}.js' --verbose --concurrency=20",
"test": "ava --verbose --concurrency=20",
"cov": "yarn nyc --reporter=html --reporter=text ava --verbose --concurrency=20",
"cov:upload": "yarn nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls",
"perf": "node lib/benchmark",
"build:es": "tsc -p tsconfig.json --declaration --module esnext --outDir ./es",
Expand All @@ -71,6 +73,9 @@
"precommit": "lint-staged",
"doc": "typedoc --options typedoc.js src"
},
"ava": {
"files": ["lib/**/__tests__/*.{test,it}.js"]
},
"lint-staged": {
"{./*,typescript/**/*}.{js,jsx,ts,tsx,css,scss,md,json}": "prettier -l",
"*.{ts,tsx}": "tslint -c tslint.json"
Expand Down
12 changes: 10 additions & 2 deletions packages/reify_ts/src/__tests__/intersection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@
* LICENSE file in the root directory of this source tree.
*/

import { STRING, NUMBER, Kind } from '../types';
import { STRING, Kind } from '../types';
import test from 'ava';
import { transformUnitTestProgram } from './util/unit';

test('intersection', t => {
transformUnitTestProgram(t, 'intersection').assertTypesEqual({
Intersection: {
kind: Kind.intersection,
types: [NUMBER, STRING],
types: [
STRING,
{
kind: Kind.record,
fields: {
a: { type: STRING },
},
},
],
},
});
// Cannot fast-check as the intersection is not inhabited.
Expand Down
2 changes: 1 addition & 1 deletion packages/reify_ts/src/__tests__/programs/intersection.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// This intersection is not inhabited, but this is not something that TypeScript checks.
export type Intersection = number & string;
export type Intersection = string & { a: string };
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type ThirdPartyTypeDefinition = {
};

const thirdPartyTypeDefinitions: ThirdPartyTypeDefinition[] = [
{ name: 'node', path: '@types/node/index.d.ts' },
// { name: 'node', path: '@types/node/index.d.ts' },
{ name: 'node_inspector', path: '@types/node/inspector.d.ts' },
{ name: 'lodash', path: '@types/lodash/index.d.ts' },
{ name: 'react', path: '@types/react/index.d.ts' },
Expand Down
56 changes: 31 additions & 25 deletions packages/reify_ts/src/__tests__/util/test_package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,38 +90,44 @@ export class TestPackage<
async yarn(
command: string[] = [],
{ mustSucceed = true, verbose = false } = {},
): Promise<{ stdout: string; stderr: string; exitCode: number }> {
return new Promise<{ stdout: string; stderr: string; exitCode: number }>(
(resolve, reject) => {
let stdout: string = '';
let stderr: string = '';

const proc = this.spawnYarn(command);
proc.on('exit', (exitCode, signal) => {
const reason = `yarn exited with code ${exitCode} and signal ${signal}; STDOUT: <<<\n${stdout}\n>>>; STDERR: <<<\n${stderr}\n>>>`;
if (verbose) {
console.log(reason);
}
if (mustSucceed && exitCode !== 0) {
reject(new Error(reason));
}
resolve({ stdout, stderr, exitCode });
});

proc.on('error', (err: Error) => {
console.error(`child process errored: ${err.toString()}`);
reject(err);
});

): Promise<{ stdout: string; stderr: string; exitCode: number | null }> {
return new Promise<{
stdout: string;
stderr: string;
exitCode: number | null;
}>((resolve, reject) => {
let stdout: string = '';
let stderr: string = '';

const proc = this.spawnYarn(command);
proc.on('exit', (exitCode, signal) => {
const reason = `yarn exited with code ${exitCode} and signal ${signal}; STDOUT: <<<\n${stdout}\n>>>; STDERR: <<<\n${stderr}\n>>>`;
if (verbose) {
console.log(reason);
}
if (mustSucceed && exitCode !== 0) {
reject(new Error(reason));
}
resolve({ stdout, stderr, exitCode });
});

proc.on('error', (err: Error) => {
console.error(`child process errored: ${err.toString()}`);
reject(err);
});

if (proc.stdout) {
proc.stdout.on('data', (data: any) => {
stdout += data.toString();
});
}

if (proc.stderr) {
proc.stderr.on('data', (data: any) => {
stderr += data.toString();
});
},
);
}
});
}
}

Expand Down
18 changes: 10 additions & 8 deletions packages/reify_ts/src/__tests__/util/ttsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { ProgramTransformationResultWrapper } from './type_util';
* The version of TypeScript to use. If you update this line, please
* update the build matrix in `.circleci/config.yml`.
*/
const TYPESCRIPT_VERSION = '3.5.1';
const TYPESCRIPT_VERSION = '3.6.4';

/**
* The constant file name where the type ASTs are stored after the
Expand Down Expand Up @@ -60,7 +60,7 @@ export class TsTestPackage extends TestPackage<TsTestPackageOptions> {
version: packageJson.version,
dependencies: {
'reify-ts': packageJson.version,
'ts-node': '^4',
'ts-node': '^8.4.1',
typescript: TYPESCRIPT_VERSION,
ttypescript: '^1.5.7',
},
Expand Down Expand Up @@ -110,7 +110,7 @@ export class TsTestPackage extends TestPackage<TsTestPackageOptions> {

/** Gets the type ASTs that are gathered by ts_plugin. */
async getProgramTransformationResult(
t: ExecutionContext<{}>,
t: ExecutionContext<unknown>,
): Promise<ProgramTransformationResultWrapper> {
return new ProgramTransformationResultWrapper(
{
Expand All @@ -136,9 +136,11 @@ export class TsWatcher implements ExternalResource {
async setup() {
this.proc = this.pkg.spawnYarn(['ttsc', '--watch']);

this.proc.stderr.on('data', (data: any) => {
console.log('STDERR:', data.toString());
});
if (this.proc.stderr) {
this.proc.stderr.on('data', (data: any) => {
console.log('STDERR:', data.toString());
});
}
}

/** @override */
Expand All @@ -163,7 +165,7 @@ export class TsWatcher implements ExternalResource {
const listener = (data: any) => {
const dataStr: string = data.toString();
if (dataStr.includes('Watching for file changes.')) {
this.proc!.stdout.removeListener('data', listener);
this.proc!.stdout!.removeListener('data', listener);
const match = dataStr.match(/Found ([0-9]+) error/);
if (!match) {
reject(new Error(`cannot find error count in <<<${dataStr}>>>`));
Expand All @@ -181,7 +183,7 @@ export class TsWatcher implements ExternalResource {
}
}
};
this.proc.stdout.on('data', listener);
this.proc.stdout!.on('data', listener);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/reify_ts/src/__tests__/util/type_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { TypeMirror } from '../../runtime/type_mirror';
export class ProgramTransformationResultWrapper {
constructor(
private readonly result: ProgramTransformationResult,
private t: ExecutionContext<{}>,
private t: ExecutionContext<unknown>,
) {}

get entries(): TypeEntry[] {
Expand Down
2 changes: 1 addition & 1 deletion packages/reify_ts/src/__tests__/util/unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { TypeExtractorOptions } from '../../engine/types';
import { SourceFileVisitorClass } from '../../engine/visitor';

export function transformUnitTestProgram(
t: ExecutionContext<{}>,
t: ExecutionContext<unknown>,
programName: string,
{
extraFiles = [],
Expand Down
6 changes: 6 additions & 0 deletions packages/reify_ts/src/engine/extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ export class TypeExtractor {
checker: ts.TypeChecker,
parentSymbol: ts.Symbol | undefined,
): Type {
if (
typeToString(type, checker).includes('globalThis = typeof globalThis')
) {
return this.warning(type.getSymbol() || parentSymbol, 'globalThis');
}

if (type.flags & ts.TypeFlags.TypeVariable && !name) {
const symbol = type.getSymbol();
return this.warning(
Expand Down
10 changes: 9 additions & 1 deletion packages/reify_ts/src/engine/internal/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,18 @@ export class TypeConversionInvariantError extends BaseError {
[
`while processing type \`${typeStr}\``,
msg,
`${cause && cause.stack}\n------`,
`${cause && getStack(cause)}\n------`,
]
.filter(it => !!it)
.join(': '),
);
}
}

function getStack(cause: Error): string {
try {
return cause.stack || '<stack unavailable>';
} catch (err) {
return `<stack unavailable: ${err}>`;
}
}
1 change: 1 addition & 0 deletions packages/reify_ts/src/engine/warnings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const WARNINGS = {
anyType: () =>
'an "any" type has been encountered; use "unknown", the type-safe counterpart of "any", to remove this warning',
neverType: () => 'a "never" type has been encountered',
globalThis: () => '"globalThis" has been encountered',
keyofType: (typeStr: string) => `the "${typeStr}" type could not be expanded`,
conditionalType: (typeStr: string) =>
`a conditional type could not be expanded: ${typeStr}`,
Expand Down
Loading

0 comments on commit 14f0cf6

Please sign in to comment.