Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type-compiler produces empty ops for some types and broken output #352

Open
wielski opened this issue Aug 16, 2022 · 5 comments
Open

type-compiler produces empty ops for some types and broken output #352

wielski opened this issue Aug 16, 2022 · 5 comments

Comments

@wielski
Copy link

wielski commented Aug 16, 2022

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.

@marcj
Copy link
Member

marcj commented Aug 16, 2022

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.

@wielski
Copy link
Author

wielski commented Aug 17, 2022

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

@marcj
Copy link
Member

marcj commented Aug 17, 2022

Yeah that's not possible due to technical restrictions

@wielski
Copy link
Author

wielski commented Aug 17, 2022

@marcj thanks for your help :)
I'll try to rebuild desired types with type-compiler

@marcus-sa
Copy link
Contributor

@wielski this will be possible when #517 lands

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants