Releases: GoogleFeud/ts-macros
Releases · GoogleFeud/ts-macros
v2.6.2
v2.6.1
Changes
- Support for typescript
5.5.x
v2.6.0
Additions
$$typeMetadata
built-in macro which gathers information on the provided type. This includes:- Properties and their names, whether they're optional or not, their stringified types, and their JSDoc tags.
- Methods and their names, their return type, their parameter names and types, and their JSDoc tags.
- You can now access the type of repetition elements (#78):
function $compareTypes<T extends unknown[]>(a: T, b: T) { +["[]", [a, b], <AT, BT>(aEl: AT, bEl: BT) => $$typeToString!<AT>() === $$typeToString!<BT>()]; } console.log($compareTypes!(["abc", 2, false, 3], ["abc", 2, true, false])); // Transpiles to: console.log([true, true, false, false]);
- Logging to the console in the playground now displays the messages in a side-panel.
Changes
- Improved literal reduction with the logical
OR
andAND
operators.true literal || non literal
, will be reduced to thetrue literal
expression.false literal || non literal
, will be reduced to thenon literal
expression.true literal && non literal
, will be reduced to thenon literal
expression.false literal && non literal
, will be reduced to thefalse literal
expression.
Bug fixes
- Fixed the
call
function not being present in theRawContext
interface in the playground. - Invalid code like
{a: 1}.b;
can longer be generated. - Fixed #77.
Deprecations
Some parts of this library negatively impact the transformer's performance and make the source code more complex to maintain while serving a fairly niche purpose. If you find these features useful, please create an issue about it! If enough people use them they won't be removed.
$$comptime
macro - While cool to have something similar to Zig's comptime macros, it's way too limited. It can realistically only be used to validate arguments passed to functions, which should be done during runtime anyway.$$loadEnv
macro - Requires an optional dependency, a similar result can be achieved using the$$readFile
macro by putting your configuration in a JSON file.$$propsOfType
macro - In favor of the$$typeMetadata
macro.
v2.5.0
Additions
- ts-macros CLI: A CLI tool now comes with ts-macros, that allows you to transform your entire project to expand all macros, and then optionally transpile to javascript. It also features a watch option, which should be used instead other watchers. Read more here.
- Support for typescript version
5.2.x
v2.4.2
v2.4.1
v2.4.0
Additions
- A second experimental transformer,
type-resolver
, that transpiles your code to typescript with all macros expanded before transpiling it to javascript. This means you can use types or exported values generated by macros in your code! - You can now export the variables defined by the
$$define
macro by passing a fourth parameter.
Changes
- You can no longer change the name of classes/enums/functions by giving them the same name as a maco parameter, use macro variables from now on:
function $setPropName(names: string) { const $name = $$ident!(names); return class $name { $test: string = "" } }
- Removed the
$$getStore
and$$setStore
built-in macro.- Use macro variables instead:
const $value = 123;
- Use macro variables instead:
- Removed the
$$inlineFunc
built-in macro.- Use the
$$inline
macro instead.
- Use the
Bug fixes
v2.3.1
v2.3.0
Additions
function $template(strs: TemplateStringsArray, ...elements: number[]) {
return +["+", [strs, elements], (string: string, el: number) => string + (el ? el + 1 : "")]
}
// Call
$template!`Hello ${1} world ${2}`;
// Result
"Hello 2 world 3";
Changes
- Remove
ttypescript
usage example (#59)
Bug fixes
- Fixes #56