diff --git a/CHANGELOG.md b/CHANGELOG.md index fa44400ddb21..6fd0b87aefb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - `[*]`: Setup building, linting and testing of TypeScript ([#7808](https://github.com/facebook/jest/pull/7808)) - `[pretty-format]`: Migrate to TypeScript ([#7809](https://github.com/facebook/jest/pull/7809)) +- `[diff-sequences]`: Migrate to Typescript ([#7820](https://github.com/facebook/jest/pull/7820)) ### Performance diff --git a/packages/diff-sequences/package.json b/packages/diff-sequences/package.json index 176da42680e1..33fc60579975 100644 --- a/packages/diff-sequences/package.json +++ b/packages/diff-sequences/package.json @@ -19,6 +19,7 @@ "node": ">= 6" }, "main": "build/index.js", + "types": "build/index.d.ts", "scripts": { "perf": "node --expose-gc perf/index.js" }, diff --git a/packages/diff-sequences/src/__tests__/__snapshots__/index.test.js.snap b/packages/diff-sequences/src/__tests__/__snapshots__/index.test.ts.snap similarity index 100% rename from packages/diff-sequences/src/__tests__/__snapshots__/index.test.js.snap rename to packages/diff-sequences/src/__tests__/__snapshots__/index.test.ts.snap diff --git a/packages/diff-sequences/src/__tests__/index.test.js b/packages/diff-sequences/src/__tests__/index.test.ts similarity index 99% rename from packages/diff-sequences/src/__tests__/index.test.js rename to packages/diff-sequences/src/__tests__/index.test.ts index 7362a8de6b00..6652c756b7fb 100644 --- a/packages/diff-sequences/src/__tests__/index.test.js +++ b/packages/diff-sequences/src/__tests__/index.test.ts @@ -4,7 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow */ import diff from '../'; @@ -16,7 +15,7 @@ describe('invalid arg', () => { describe('length', () => { test('is not a number', () => { expect(() => { - diff(('0': any), 0, isCommon, foundSubsequence); + diff('0' as any, 0, isCommon, foundSubsequence); }).toThrow(/aLength/); }); test('Infinity is not a safe integer', () => { @@ -50,12 +49,12 @@ describe('invalid arg', () => { describe('callback', () => { test('null is not a function', () => { expect(() => { - diff(0, 0, (null: any), foundSubsequence); + diff(0, 0, null as any, foundSubsequence); }).toThrow(/isCommon/); }); test('undefined is not a function', () => { expect(() => { - diff(0, 0, isCommon, (undefined: any)); + diff(0, 0, isCommon, undefined as any); }).toThrow(/foundSubsequence/); }); }); diff --git a/packages/diff-sequences/src/index.js b/packages/diff-sequences/src/index.ts similarity index 97% rename from packages/diff-sequences/src/index.js rename to packages/diff-sequences/src/index.ts index 9d7d4bb3488c..3a676e0575dc 100644 --- a/packages/diff-sequences/src/index.js +++ b/packages/diff-sequences/src/index.ts @@ -4,7 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow */ // This diff-sequences package implements the linear space variation in @@ -66,10 +65,10 @@ type FoundSubsequence = ( ) => void; // Either original functions or wrapped to swap indexes if graph is transposed. -type Callbacks = {| - foundSubsequence: FoundSubsequence, - isCommon: IsCommon, -|}; +type Callbacks = { + foundSubsequence: FoundSubsequence; + isCommon: IsCommon; +}; // Indexes in sequence a of last point of forward or reverse paths in graph. // Myers algorithm indexes by diagonal k which for negative is bad deopt in V8. @@ -81,25 +80,25 @@ type Indexes = Array; // Division of index intervals in sequences a and b at the middle change. // Invariant: intervals do not have common items at the start or end. -type Division = {| +type Division = { // The end of interval preceding division is open like array slice method. - nChangePreceding: number, // number of change items - aEndPreceding: number, - bEndPreceding: number, + nChangePreceding: number; // number of change items + aEndPreceding: number; + bEndPreceding: number; - nCommonPreceding: number, // 0 if no common items preceding middle change - aCommonPreceding: number, // ignore prop value if nCommonPreceding === 0 - bCommonPreceding: number, // ignore prop value if nCommonPreceding === 0 + nCommonPreceding: number; // 0 if no common items preceding middle change + aCommonPreceding: number; // ignore prop value if nCommonPreceding === 0 + bCommonPreceding: number; // ignore prop value if nCommonPreceding === 0 - nCommonFollowing: number, // 0 if no common items following middle change - aCommonFollowing: number, // ignore prop value if nCommonFollowing === 0 - bCommonFollowing: number, // ignore prop value if nCommonFollowing === 0 + nCommonFollowing: number; // 0 if no common items following middle change + aCommonFollowing: number; // ignore prop value if nCommonFollowing === 0 + bCommonFollowing: number; // ignore prop value if nCommonFollowing === 0 // The start of interval following division is closed like array slice method. - nChangeFollowing: number, // number of change items - aStartFollowing: number, - bStartFollowing: number, -|}; + nChangeFollowing: number; // number of change items + aStartFollowing: number; + bStartFollowing: number; +}; const pkg = 'diff-sequences'; // for error messages const NOT_YET_SET = 0; // small int instead of undefined to avoid deopt in V8 diff --git a/packages/diff-sequences/tsconfig.json b/packages/diff-sequences/tsconfig.json new file mode 100644 index 000000000000..7bb06bce6d20 --- /dev/null +++ b/packages/diff-sequences/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build" + } +}