fddtsc
foundatsion declaration typescript file compiler
usage
@axel-hq
/
fddtsc
: foundatsion's d.ts generator
fddtsc
[flag
[
arg
], ...]
-help, -h
Print this message.
--project, -p
(
path
) Use a different tsconfig.json file. Either a directory containing tsconfig.json or a file.
--outDir
(
path
) Specify an output folder for all emitted files. Note that declarationDir overrides this.
--declarationDir
(
path
) Specify the output directory for generated declaration files.
ffaq (fake frequently asked questions)
Who is this for?
Anyone that uses @axel-hq/foundatsion who plans to publish a library that would expose newtypes through d.ts files.What does it do?
Imagine you wanted to expose a method likeadd1(a: F.uint): F.uint)`
.
Without some special compiler magic, you'd have to create a wrapped add1
which took numbers instead of foundatsion types; foundatsion types are hard
to consume and create for non-foundatsion users.
This, here, is the compiler magic that makes newtypes disappear within d.ts files.
transform calls //!
Leading comments (comments directly above a type) trigger type transforms.
-
foundatsion::newtype
: every reference to this type is replaced withunknown
. -
foundatsion::unwrap
: every reference to this type is replaced with it's first type argument. -
foundatsion::bake
: this type's simplification is baked into the output.
// @file example.ts
//! foundatsion::unwrap
type bar<baz> = never;
type reverse_string<s extends string> =
s extends `${infer head}${infer tail}`
? `${reverse_string<tail>}${head}`
: "";
export type so = bar<"shouldn't this be never?">;
//! foundatsion::bake
export type baked = reverse_string<"Hello, World!">;
// @file example.d.ts
export type so = "shouldn't this be never?";
export type baked = "!dlroW ,olleH";
for Reasons We Do Not Fully Understand, neither newtype nor unwrap work all the time
for developers
make install
make build
-
make install
(again to install what you just built into the test) make test