Skip to content

Allow lazily define type in annotations / ES modules #189

@perceptron8

Description

@perceptron8

Because of somewhat eager

const typeToTest = typeThunk?.();

it's currently impossible to define types truly lazily.
Above call causes serious problems when ES modules are being used.

To reproduce, you can review and

git clone https://github.com/perceptron8/TypedJSONReferenceError
cd TypedJSONReferenceError
yarn install
yarn test

-> ReferenceError: Cannot access 'A' before initialization.

"emitDecoratorMetadata" (tsconfig.json) is deliberately set to false, so it's not because of microsoft/TypeScript#4521.

If you change "type" to "commonjs" (package.json) and "compilerOptions" / "module" to "CommonJS" (tsconfig.json), test will run fine. BTW that's exactly why your lazy-types.spec.ts isn't failing:

"module": "CommonJS",

I know that typeToTest is currently being used to check for special property types, but maybe this checking could be deferred or - in case of jsonMemberDecoratorFactory - skipped at all?


This issue refers to: #139.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions