Skip to content

Commit

Permalink
feat: downlevel template literal types < 4.1 (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyJonas and JeremyJonas authored Oct 19, 2022
1 parent 5188cd4 commit fb8f2de
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 1 deletion.
2 changes: 2 additions & 0 deletions baselines/reference/ts3.4/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ export declare const foo: {
};
};
export type IR = IteratorResult<number>;
/** Template Literal - supported since 4.1 < should be StringKeyword */
export type TTemplateLiteral = string;
2 changes: 2 additions & 0 deletions baselines/reference/ts3.5/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ export declare const foo: {
};
};
export type IR = IteratorResult<number>;
/** Template Literal - supported since 4.1 < should be StringKeyword */
export type TTemplateLiteral = string;
2 changes: 2 additions & 0 deletions baselines/reference/ts3.6/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,5 @@ export declare const foo: {
};
};
export type IR = IteratorResult<number, string>;
/** Template Literal - supported since 4.1 < should be StringKeyword */
export type TTemplateLiteral = string;
2 changes: 2 additions & 0 deletions baselines/reference/ts3.7/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,5 @@ export declare const foo: {
};
};
export type IR = IteratorResult<number, string>;
/** Template Literal - supported since 4.1 < should be StringKeyword */
export type TTemplateLiteral = string;
2 changes: 2 additions & 0 deletions baselines/reference/ts3.8/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,5 @@ export declare const foo: {
};
};
export type IR = IteratorResult<number, string>;
/** Template Literal - supported since 4.1 < should be StringKeyword */
export type TTemplateLiteral = string;
2 changes: 2 additions & 0 deletions baselines/reference/ts3.9/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,5 @@ export declare const foo: {
};
};
export type IR = IteratorResult<number, string>;
/** Template Literal - supported since 4.1 < should be StringKeyword */
export type TTemplateLiteral = string;
2 changes: 2 additions & 0 deletions baselines/reference/ts4.0/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,5 @@ export declare const foo: {
};
};
export type IR = IteratorResult<number, string>;
/** Template Literal - supported since 4.1 < should be StringKeyword */
export type TTemplateLiteral = string;
2 changes: 2 additions & 0 deletions baselines/reference/ts4.1/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,5 @@ export declare const foo: {
};
};
export type IR = IteratorResult<number, string>;
/** Template Literal - supported since 4.1 < should be StringKeyword */
export type TTemplateLiteral = `${string}abc${string}`;
2 changes: 2 additions & 0 deletions baselines/reference/ts4.2/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,5 @@ export declare const foo: {
};
};
export type IR = IteratorResult<number, string>;
/** Template Literal - supported since 4.1 < should be StringKeyword */
export type TTemplateLiteral = `${string}abc${string}`;
2 changes: 2 additions & 0 deletions baselines/reference/ts4.3/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,5 @@ export declare const foo: {
};
};
export type IR = IteratorResult<number, string>;
/** Template Literal - supported since 4.1 < should be StringKeyword */
export type TTemplateLiteral = `${string}abc${string}`;
2 changes: 2 additions & 0 deletions baselines/reference/ts4.4/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,5 @@ export declare const foo: {
};
};
export type IR = IteratorResult<number, string>;
/** Template Literal - supported since 4.1 < should be StringKeyword */
export type TTemplateLiteral = `${string}abc${string}`;
2 changes: 2 additions & 0 deletions baselines/reference/ts4.5/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ export declare const foo: {
};
};
export type IR = IteratorResult<number, string>;
/** Template Literal - supported since 4.1 < should be StringKeyword */
export type TTemplateLiteral = `${string}abc${string}`;
2 changes: 2 additions & 0 deletions baselines/reference/ts4.6/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ export declare const foo: {
};
};
export type IR = IteratorResult<number, string>;
/** Template Literal - supported since 4.1 < should be StringKeyword */
export type TTemplateLiteral = `${string}abc${string}`;
2 changes: 2 additions & 0 deletions baselines/reference/ts4.7/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ export declare const foo: {
};
};
export type IR = IteratorResult<number, string>;
/** Template Literal - supported since 4.1 < should be StringKeyword */
export type TTemplateLiteral = `${string}abc${string}`;
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ function doTransform(checker, targetVersion, k) {
}
}

if (semver.lt(targetVersion, "4.1.0") && n.kind === ts.SyntaxKind.TemplateLiteralType) {
// TemplateLiteralType added in 4.2
// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-1.html#template-literal-types
return ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
}

if (semver.lt(targetVersion, "3.6.0") && ts.isGetAccessor(n)) {
// get x(): number => x: number
let flags = ts.getCombinedModifierFlags(n);
Expand Down
5 changes: 4 additions & 1 deletion test/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,7 @@ export declare const foo: {
};
};

export type IR = IteratorResult<number, string>;
export type IR = IteratorResult<number, string>;

/** Template Literal - supported since 4.1 < should be StringKeyword */
export type TTemplateLiteral = `${string}abc${string}`;

0 comments on commit fb8f2de

Please sign in to comment.