Merged
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
0.27.0
Overview
Revision 0.27.0 adds support for runtime Template Literal Types. This revision does not include any functional breaking changes but does rename some public type aliases. As such this revision requires a minor semver increment.
Contents
Template Literal Types
Revision 0.27.0 adds support for Template Literal types. These types operate as a form of computed
TUnion<TLiteral<string>>. TypeBox encodes template literals using a subset of ECMA 262 regular erxpressions which are applied topatternproperties of typestring. This encoding enables JSON Schema validators to assert using existing regular expression checks.TypeScript
TypeScript defines Template Literals using back tick quoted strings which may include embedded union groups.
TypeBox
TypeBox defines Template Literals using the
TemplateLiteralfunction. This function accepts a sequence of TLiteral, TString, TNumber, TInteger and TBigInt which describe a sequence concatenations. The embedded TUnion type defines an option group which can later be expanded into a set ofTLiteral<string>. This expansion enables Template Literal types to also be used as Record keys.TemplateLiteralParser
Template Literal types are encoded as
stringpatterns. Because these types also need to act as composable union types, Revision 0.27.0 includes an expression parser / generator system specifically for regular expressions. This system is used during composition to allow templates to compose with other types, but can also be used in isolation to generate string sequences for the supported expression grammar. This functionality may be provided as standard on theValue.*sub module in subsequent revisions.The following generates a 8-bit binary sequence for the given expression.
Workbench
To assist with TypeScript alignment and to prototype new features. A new web based compiler tool has been written that allows interactive cross compiling between TypeScript and TypeBox. This tool will be enhanced seperately from the TypeBox project, but can be used to quickly generate TypeBox type definitions from existing TypeScript types.
TypeBox Workbench Application
TypeBox Workbench Project
Breaking Changes
The following are breaking changes in Revision 0.27.0
TSelf renamed to TThis
This rename is to align with TypeScript interfaces. Unlike
typealiases, TypeScriptinterfacetypes include a implicitthistype. This change relates specifically to TypeBox's current Recursive type which passes theTThisparameter via callback. TheTThisparameter can be seen as analogous to the implicit TypeScript interfacethis.Consider the following.
Future revisions may rename
RecurisvetoInterface, but for now, just theTSelfhas been renamed.