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

[bug] Syntax error in TypeScript type defination files #7325

Closed
TechQuery opened this issue Nov 18, 2021 · 4 comments · Fixed by #7426
Closed

[bug] Syntax error in TypeScript type defination files #7325

TechQuery opened this issue Nov 18, 2021 · 4 comments · Fixed by #7426

Comments

@TechQuery
Copy link

TechQuery commented Nov 18, 2021

🎛 Configuration

package.json

{
    "source": "src/index.ts",
    "main": "dist/index.js",
    "module": "dist/index.esm.js",
    "types": "dist/index.d.ts",
    "dependencies": {
        "@swc/helpers": "^0.2.14",
        "web-utility": "^2.9.6"
    },
    "peerDependencies": {
        "katex": "^0.15.1",
        "react": ">=16",
        "react-bootstrap": "^1.6.4"
    },
    "devDependencies": {
        "@parcel/packager-ts": "^2.0.1",
        "@parcel/transformer-typescript-types": "^2.0.1",
        "@types/jest": "^27.0.2",
        "@types/katex": "^0.11.1",
        "@types/react": "^16.14.21",
        "husky": "^7.0.4",
        "jest": "^27.3.1",
        "katex": "^0.15.1",
        "lint-staged": "^12.0.3",
        "open-cli": "^7.0.1",
        "parcel": "^2.0.1",
        "prettier": "^2.4.1",
        "react": "^16.14.0",
        "react-bootstrap": "^1.6.4",
        "ts-jest": "^27.0.7",
        "typedoc": "^0.22.9",
        "typedoc-plugin-mdn-links": "^1.0.4",
        "typescript": "^4.5.2"
    },
    "browserslist": "> 0.5%, last 2 versions, not dead",
    "targets": {
        "main": {
            "optimize": false
        }
    }
}

tsconfig.json

{
    "compilerOptions": {
        "target": "ES5",
        "esModuleInterop": true,
        "jsx": "react",
        "lib": ["ES2021", "DOM"]
    },
    "include": ["src/**/*"]
}

🤔 Expected Behavior

Generate right Type Defination files for libraries, as what Parcel 2.0.0 did.

😯 Current Behavior

dist/index.d.ts

import { PickData as  } from "web-utility";
import { PropsWithoutRef as , RefCallback as , PropsWithChildren as  } from "react";
import { type _PickData1 as  } from "web-utility/source/data";

🌍 Your Environment

Software Version(s)
Parcel 2.0.1
TypeScript 4.5.2
Node 14.17.6
Yarn 1.22.15
Operating System Windows 10 Pro 21H1
@TechQuery
Copy link
Author

TechQuery commented Nov 18, 2021

Parcel 2.0.0 + TypeScript 4.3.5 has no syntax error, but loses some export type defination:

import XXX from './XXX';

export const doSomething = () => console.log(XXX);

export { default as XXX } from './XXX';

and same Type warnings appear:

image

@benqus
Copy link

benqus commented Nov 24, 2021

I'm getting the same - sounds like this is a TypeScript issue then?

Parcel 2.0.0 + TypeScript 4.3.5 has no syntax error, but loses some export type defination:

import XXX from './XXX';

export const doSomething = () => console.log(XXX);

export { default as XXX } from './XXX';

and same Type warnings appear:

image

As per @TechQuery suggestions:
Reverted typescript from ^4.5.2 to 4.3.5 and using

export { MyModule } from './MyModule';

That worked!

@benpigchu
Copy link

I encountered a similar problem with Parcel 2.0.1 and Typescript 4.5.2. Parcel 2.0.1 and Typescript 4.4.4 works for me.

@benpigchu
Copy link

Typescript 4.5 added type Modifiers on Import Names. As a result, the API for ts.createImportSpecifier has changed, and therefore breaks the usage of the API in transformers for typescript-types

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

Successfully merging a pull request may close this issue.

5 participants