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

typia generated can't load type #538

Closed
sunrabbit123 opened this issue Mar 3, 2023 · 9 comments
Closed

typia generated can't load type #538

sunrabbit123 opened this issue Mar 3, 2023 · 9 comments
Assignees
Labels
bug Something isn't working invalid This doesn't seem right

Comments

@sunrabbit123
Copy link
Contributor

Bug Report

error is simple

import { ContainsFooOrBar } from "types";
import { assert } from "typia";

assert({} as ContainsFooOrBar);
type FooOrBar = "foo" | "bar";
export type ContainsFooOrBar = {
    foo : FooOrBar;
    bar : FooOrBar;
}
import { ContainsFooOrBar } from "../types";
import { assert } from "typia";
((input: any): {    foo: FooOrBar;    bar: FooOrBar;} => {
    const $guard = (assert as any).guard;
    ((input: any, _path: string, _exceptionable: boolean = true): input is {    foo: FooOrBar;    bar: FooOrBar;} => {
        const $ao0 = (input: any, _path: string, _exceptionable: boolean = true): boolean => ("foo" === input.foo || "bar" === input.foo || $guard(_exceptionable, {
            path: _path + ".foo",
            expected: "(\"bar\" | \"foo\")",
            value: input.foo
        })) && ("foo" === input.bar || "bar" === input.bar || $guard(_exceptionable, {
            path: _path + ".bar",
            expected: "(\"bar\" | \"foo\")",
            value: input.bar
        }));
        return ("object" === typeof input && null !== input || $guard(true, {
            path: _path + "",
            expected: "Resolve<ContainsFooOrBar>",
            value: input
        })) && $ao0(input, _path + "", true);
    })(input, "$input", true);
    return input;
})({} as ContainsFooOrBar);

But, FooOrBar is not imported
It cause TS2304 Cannot find name 'FooOrBar'

settings

{
  "name": "typia_playground",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "devDependencies": {
    "commander": "^10.0.0",
    "inquirer": "^8.2.5",
    "ts-node": "^10.9.1",
    "ttypescript": "^1.5.15",
    "typescript": "^4.9.5"
  },
  "dependencies": {
    "typia": "^3.6.2"
  }
}
{
    "compilerOptions": {
        "module": "commonjs",
        "target": "ESNext",
        "sourceMap": true,
        "declaration": true,
        "removeComments": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "allowSyntheticDefaultImports": true,
        "outDir": "./dist",
        "baseUrl": "./",
        "incremental": true,
        "skipLibCheck": true,
        "strict": true,
        "noImplicitAny": true,
        "esModuleInterop": true,
        "resolveJsonModule": true,
        "plugins": [
            {
                "transform": "typia/lib/transform"
            },
        ]
    }
}
@samchon samchon self-assigned this Mar 3, 2023
@samchon samchon added bug Something isn't working invalid This doesn't seem right labels Mar 3, 2023
@samchon
Copy link
Owner

samchon commented Mar 3, 2023

It is a bug cleary, but no way to fix it for a while, as I don't know how to.

Therefore, I suggest two ways:

1. Declare interface instead of type

When declare a type, then it works as an alias symbol.

It is the reason why return type of assert function became an object literal expression.

If you change ContainsFooOrBar as an interface, then the bug would not be occured more.

2. Specify generic argument

If you specify generic argument like assert<ContainsFooOrBar>(input), then it would be fixed.

@samchon
Copy link
Owner

samchon commented Mar 3, 2023

I will try to fix this bug by implementing advanced type analyzer which can write import statements, but cannot sure success.

@samchon
Copy link
Owner

samchon commented Apr 13, 2023

Not easy to implement in generation mode.

@samchon samchon closed this as not planned Won't fix, can't repro, duplicate, stale Apr 13, 2023
@AlexRMU
Copy link
Contributor

AlexRMU commented Aug 15, 2024

Is it fixed?

@samchon
Copy link
Owner

samchon commented Aug 15, 2024

Maybe, try it.

@AlexRMU
Copy link
Contributor

AlexRMU commented Aug 17, 2024

Everything is working fine for me.
Maybe the problem is in the ts config and you need to write

import { type ContainsFooOrBar } from "types";

instead of

import { ContainsFooOrBar } from "types";

@AlexRMU
Copy link
Contributor

AlexRMU commented Aug 21, 2024

@AlexRMU
Copy link
Contributor

AlexRMU commented Aug 21, 2024

Related:
ryoppippi/unplugin-typia#283
#1225

@AlexRMU
Copy link
Contributor

AlexRMU commented Aug 21, 2024

Currently, tsconfig aliases are not supported, you need to use relative imports or vite aliases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

3 participants