Skip to content

Commit

Permalink
Fixed incorrect caching of symbols usage values
Browse files Browse the repository at this point in the history
Fixes #318
  • Loading branch information
timocov committed Apr 17, 2024
1 parent d3c2225 commit 897a5d5
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/types-usage-evaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ export class TypesUsageEvaluator {

visitedSymbols.add(fromSymbol);

return this.setUsageCacheValue(fromSymbol, toSymbol, false);
// note that we can't save negative result here because it might be not a final one
// because we might ended up here because of `visitedSymbols.has(symbol)` check above
// while actually checking that `symbol` symbol and we will store all its "children" as `false`
// while in reality some of them might be `true` because of cross-references or using the same children symbols
return false;
}

private setUsageCacheValue(fromSymbol: ts.Symbol, toSymbol: ts.Symbol, value: boolean): boolean {
Expand Down
5 changes: 5 additions & 0 deletions tests/e2e/test-cases/recursive-types/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { TestCaseConfig } from '../../test-cases/test-case-config';

const config: TestCaseConfig = {};

export = config;
1 change: 1 addition & 0 deletions tests/e2e/test-cases/recursive-types/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('../run-test-case').runTestCase(__dirname);
3 changes: 3 additions & 0 deletions tests/e2e/test-cases/recursive-types/input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { FirstType } from './types';

export type MyType = FirstType<string>;
6 changes: 6 additions & 0 deletions tests/e2e/test-cases/recursive-types/output.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export type ThirdType = number;
export type SecondType<T, V> = T extends any ? V : FirstType<T>;
export type FirstType<T> = SecondType<ThirdType, T>;
export type MyType = FirstType<string>;

export {};
5 changes: 5 additions & 0 deletions tests/e2e/test-cases/recursive-types/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type ThirdType = number;

type SecondType<T, V> = T extends any ? V : FirstType<T>;

export type FirstType<T> = SecondType<ThirdType, T>;

0 comments on commit 897a5d5

Please sign in to comment.