-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Object properties can now get lazy processed. (+more) - Recursive types now work, but don't yet enforce consistency. * Undefined properties are now optional. * Refactorization - Reduced the unnecessary prevelence of OptionalUndefined - Removed the redundant "_infered" holder property. * Fixed nested recursive types. * Fixed the typed recursive tests. * Updated the README, describing recursive types. * Fixed the array.test naming. * 1.1.0
- Loading branch information
Showing
15 changed files
with
278 additions
and
57 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
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,53 @@ | ||
// | ||
// Run with `npm run example:recursiveTypes` | ||
// | ||
|
||
import { INT, object, Parsed, ParsedConcrete, STRING, typedGeneric, typedObject, TypeToken } from 'typed-binary'; | ||
|
||
interface ExpressionBase {} | ||
|
||
interface MultiplyExpression extends ExpressionBase { | ||
type: 'multiply'; | ||
a: Expression; | ||
b: Expression; | ||
} | ||
|
||
interface NegateExpression extends ExpressionBase { | ||
type: 'negate'; | ||
inner: Expression; | ||
} | ||
|
||
type IntLiteralExpression = ParsedConcrete<ExpressionBase, typeof IntLiteralExpression, 'int_literal'>; | ||
const IntLiteralExpression = object({ | ||
value: INT, | ||
}); | ||
|
||
type Expression = MultiplyExpression|NegateExpression|IntLiteralExpression; | ||
const Expression = typedGeneric(new TypeToken<Expression>(), { | ||
name: STRING, | ||
}, { | ||
'multiply': typedObject<MultiplyExpression>(() => ({ | ||
a: Expression, | ||
b: Expression, | ||
})), | ||
'negate': typedObject<NegateExpression>(() => ({ | ||
inner: Expression, | ||
})), | ||
'int_literal': IntLiteralExpression | ||
}); | ||
|
||
const expr: Parsed<typeof Expression> = { | ||
type: 'multiply', | ||
a: { | ||
type: 'negate', | ||
inner: { | ||
type: 'int_literal', | ||
value: 15, | ||
} | ||
}, | ||
b: { | ||
type: 'int_literal', | ||
value: 2, | ||
}, | ||
}; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export * from './structure'; | ||
export * from './describe'; | ||
export * from './io'; | ||
export type { Parsed } from './utilityTypes'; | ||
export type { Parsed, ParsedConcrete } from './utilityTypes'; |
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.