Skip to content

Commit

Permalink
fix(typescript): restore support for typescript 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Pmyl authored Sep 18, 2020
1 parent fb85aaf commit 825cc01
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 14 deletions.
6 changes: 3 additions & 3 deletions definitelyTypedTests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions definitelyTypedTests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"author": "",
"license": "ISC",
"dependencies": {
"cross-var": "^1.1.0",
"dotenv": "^8.2.0",
"ttypescript": "^1.5.10",
"typescript": "^4.0.2",
"upath": "^1.2.0",
"cross-var": "^1.1.0"
"typescript": "^3.9.7",
"upath": "^1.2.0"
}
}
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"ts-node": "^9.0.0",
"tsconfig-paths": "^3.9.0",
"ttypescript": "1.5.10",
"typescript": "^4.0.2",
"typescript": "^3.9.7",
"webpack": "^4.44.1",
"webpack-cli": "^3.3.12",
"webpack-merge": "^5.1.2",
Expand Down
17 changes: 16 additions & 1 deletion src/transformer/descriptor/tuple/tuple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ export function GetTupleDescriptor(
scope: Scope
): ts.Expression {
return ts.createArrayLiteral(
node.elements.map((e: ts.TypeNode) => GetDescriptor(e, scope))
getDescriptorFromTypeNodes(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
((node as any).elementTypes as ts.NodeArray<ts.TypeNode>) ||
// Typescript 4 doesn't have elementTypes but it does have elements, to support both versions
// this casting is needed.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
((node as any).elements as ts.NodeArray<ts.TypeNode>),
scope
)
);
}

function getDescriptorFromTypeNodes(
nodes: ts.NodeArray<ts.TypeNode>,
scope: Scope
): ts.Expression[] {
return nodes.map((e: ts.TypeNode) => GetDescriptor(e, scope));
}
5 changes: 2 additions & 3 deletions src/transformer/mockDefiner/mockDefiner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,8 @@ export class MockDefiner {
);
}

// NOTE: TypeScript does not support inference through has/get, but we know
// for a fact that the result here is a string!
return this._declarationCache.get(declaration) as string;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return this._declarationCache.get(declaration)!;
}

public registerMockFor(
Expand Down

0 comments on commit 825cc01

Please sign in to comment.