Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support for TS 4.1 mapped types + string literal types
Resolves #1397
- Loading branch information
Showing
59 changed files
with
3,491 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Type } from "./abstract"; | ||
|
||
/** | ||
* TS 4.1 template literal types | ||
* ```ts | ||
* type Z = `${'a' | 'b'}${'a' | 'b'}` | ||
* ``` | ||
*/ | ||
export class TemplateLiteralType extends Type { | ||
readonly type = "template-literal"; | ||
|
||
head: string; | ||
tail: [Type, string][]; | ||
|
||
constructor(head: string, tail: [Type, string][]) { | ||
super(); | ||
this.head = head; | ||
this.tail = tail; | ||
} | ||
|
||
clone(): Type { | ||
return new TemplateLiteralType( | ||
this.head, | ||
this.tail.map(([type, text]) => [type.clone(), text]) | ||
); | ||
} | ||
|
||
equals(other: Type): boolean { | ||
return ( | ||
other instanceof TemplateLiteralType && | ||
this.head === other.head && | ||
this.tail.length === other.tail.length && | ||
this.tail.every(([type, text], i) => { | ||
return ( | ||
type.equals(other.tail[i][0]) && text === other.tail[i][1] | ||
); | ||
}) | ||
); | ||
} | ||
|
||
toString() { | ||
return [ | ||
"`", | ||
this.head, | ||
...this.tail.map(([type, text]) => { | ||
return "${" + type + "}" + text; | ||
}), | ||
"`", | ||
].join(""); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.