deepkit-framework
deepkit-framework copied to clipboard
type-compiler produces empty ops for some types and broken output
type-compiler produces empty ops for type Result
from https://github.com/traverse1984/oxide.ts
import { Result } from 'oxide.ts';
export type MyResult = Result<number, Error>;
causes broken output:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.__ΩMyResult = void 0;
const __ΩMyResult; <--- empty
exports.__ΩMyResult = __ΩMyResult;
//# sourceMappingURL=index.js.map
with error 'Const declarations' require an initialization value.
Result
is both type and a class constructor.
It happens because of extractPackStructOfTypeReference
calls for extractPackStructOfType
with node FunctionDeclaration
, that stops working because of config.mode
is never
.
I suspect it happens because of findReflectionFromPath
reading tsconfig.json
from oxide.ts inside node_modules folder, and returns never cause there is no reflection field.
Yeah oxide.ts was not built using the type-compiler, so all their types will be excluded. In your case this results in an error since excluded types are not handled as any
or unknown
. So, the fix is to emit __ΩMyResult
as any (or unknown) bytecode.
Taking a types from third party npm modules would be helpful. In my case I want to deserialize json with optionable fields, using interface like this:
import { Option } from 'oxide.ts';
interface MyOptionableStruct {
myOptionableField: Option<number>;
}
maybe it possible to build type declaration reflection for external modules by adding an extra type for this purpose? like this:
import { Result } from 'oxide.ts';
import { TypeReference } from '@deepkit/type';
export type MyResult = Result<number, Error>; // reflects as any
export type MyResultRef = TypeReference<Result<number, Error>>; // reflects as real result type
export type MyResultRef = Result<number, Error> && TypeReference; // or this way
Yeah that's not possible due to technical restrictions
@marcj thanks for your help :) I'll try to rebuild desired types with type-compiler
@wielski this will be possible when https://github.com/deepkit/deepkit-framework/pull/517 lands