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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated Types are Broken #7488

Closed
jvanderen1 opened this issue Dec 26, 2021 · 8 comments
Closed

Generated Types are Broken #7488

jvanderen1 opened this issue Dec 26, 2021 · 8 comments

Comments

@jvanderen1
Copy link

jvanderen1 commented Dec 26, 2021

馃悰 bug report

Using the new fix from #7424, I would have thought the types issue would have resolved my issue in #6815. However, the types generated result in broken import statements:

types.d.ts

import { ReactNode as , ComponentType as  } from "react";
interface ContainerProviderProps<State = void> {
    initialState?: State;
    children: ReactNode;
}
interface Container<V, S = void> {
    Provider: ComponentType<ContainerProviderProps<S>>;
    useContext: () => V;
}
interface ContainerOptions {
    displayName?: string;
}
type UseHook<V, S> = (initialState?: S) => V;
export function createContainer<V, S = void>(useHook: UseHook<V, S>, options?: ContainerOptions): Container<V, S>;

//# sourceMappingURL=types.d.ts.map

As shown, the line import { ReactNode as , ComponentType as } from "react"; has incomplete syntax (missing identifiers).

馃帥 Configuration (.babelrc, package.json, cli command)

package.json

{
  "name": "@jvanderen1/unstated-next",
  "version": "1.0.0",
  "description": "Up-to-date version of everyone's favorite state management library unstated-next",
  "types": "dist/types.d.ts",
  "keywords": [
    "unstated",
    "react",
    "hooks",
    "context",
    "state",
    "react-hooks"
  ],
  "repository": {
    "type": "git",
    "url": "https://github.com/jvanderen1/unstated-next"
  },
  "license": "MIT",
  "author": "<livetoscout@gmail.com>",
  "sideEffects": false,
  "main": "dist/unstated-next.cjs.js",
  "module": "dist/unstated-next.esm.js",
  "source": "src/index.ts",
  "browser": "dist/unstated-next.umd.js",
  "scripts": {
    "build": "parcel build",
    "clean": "npm run clean:dist && npm run clean:types && npm run clean:node-modules",
    "clean:dist": "rimraf dist/",
    "clean:node-modules": "rimraf node_modules/",
    "clean:types": "tsc --build --clean",
    "clean-install": "npm run clean && npm install",
    "dev": "parcel example/index.html",
    "lint": "eslint \"**/*.{ts,tsx}\"",
    "lint:fix": "npm run lint -- --fix",
    "prepare": "husky install",
    "pretty": "prettier --check \"**/*.{ts,tsx}\"",
    "pretty:fix": "prettier --write \"**/*.{ts,tsx}\"",
    "test": "",
    "types-check": "tsc --skipLibCheck --noEmit"
  },
  "devDependencies": {
    "@parcel/packager-ts": "^2.0.0-nightly.954",
    "@parcel/transformer-typescript-types": "^2.0.0-nightly.954",
    "@swc/cli": "^0.1.55",
    "@swc/core": "^1.2.123",
    "@types/node": "^17.0.5",
    "@types/react": "latest",
    "@types/react-dom": "latest",
    "@typescript-eslint/eslint-plugin": "^5.8.0",
    "@typescript-eslint/parser": "^5.8.0",
    "eslint": "^8.5.0",
    "eslint-plugin-react": "^7.28.0",
    "eslint-plugin-react-hooks": "^4.3.0",
    "husky": "^7.0.4",
    "lint-staged": "^12.1.4",
    "parcel": "^2.0.0-nightly.952",
    "prettier": "^2.5.1",
    "prop-types": "latest",
    "react": "latest",
    "react-dom": "latest",
    "ts-node": "^10.4.0",
    "typescript": "^4.5.4"
  },
  "peerDependencies": {
    "prop-types": ">= 15.5.0",
    "react": ">= 16.8.0"
  },
  "volta": {
    "node": "16.13.1"
  }
}

.swcrc

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "decorators": true,
      "dynamicImport": true,
      "tsx": true
    },
    "transform": {
      "legacyDecorator": true,
      "decoratorMetadata": true
    },
    "target": "es2020",
    "loose": true
  },
  "module": {
    "noInterop": false,
    "type": "commonjs",
    "strict": true,
    "strictMode": true,
    "lazy": true
  },
  "sourceMaps": true
}

馃 Expected Behavior

I expect types to be generated correctly.

馃槸 Current Behavior

Types are not generated correctly.

Temp

馃拋 Possible Solution

Most likely will involve more fixes to TSModuleGraph.js

馃敠 Context

I'd like to generate types for downstream users of @jvanderen1/unstated-next.

馃捇 Code Sample

Github repository: https://github.com/jvanderen1/unstated-next

馃實 Your Environment

Note: These nightly builds do still contain an error originally demonstrated in #6815. To resolve, follow the following: #6815 (comment)

Software Version(s)
parcel ^2.0.0-nightly.952
@parcel/packager-ts ^2.0.0-nightly.954
@parcel/transformer-typescript-types ^2.0.0-nightly.954
Node 16.13.1
npm/Yarn 8.1.2
Operating System Windows 11
@mischnic
Copy link
Member

This was already fixed by #7426

But I think you didn't install that change.

@jvanderen1
Copy link
Author

What versions of nightly need to be installed?

@mischnic
Copy link
Member

I cloned your repo at jvanderen1/unstated-next@c934929 and used Yarn instead of npm to workaround #7489.
Then it worked just fined

@jvanderen1
Copy link
Author

Thank you very much! I love how awesome the dev's have been 馃挴

@selfagency
Copy link

@mischnic I just tried installing the nightlies and I'm still running into the bad type compilation issue.

  "devDependencies": {
    "@babel/core": "^7.16.7",
    "@babel/preset-env": "^7.16.7",
    "@babel/preset-typescript": "^7.16.7",
    "@parcel/babel-preset-env": "^2.0.0-nightly.961",
    "@parcel/config-default": "^2.0.0-nightly.961",
    "@parcel/core": "^2.0.0-nightly.961",
    "@parcel/packager-ts": "^2.0.0-nightly.961",
    "@parcel/transformer-typescript-types": "^2.0.0-nightly.961",
    "@parcel/validator-typescript": "^2.0.0-nightly.961",
    "@types/jest": "^27.4.0",
    "@types/node": "^17.0.5",
    "@typescript-eslint/eslint-plugin": "^5.8.1",
    "@typescript-eslint/parser": "^5.8.1",
    "eslint": "^8.5.0",
    "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-jest": "^25.3.3",
    "jest": "^27.4.5",
    "parcel": "^2.0.0-nightly.961",
    "prettier": "^2.5.1",
    "typescript": "^4.5.4"
  }

Result:

import { EventEmitter as  } from "events";
import { Getter as , Options as , Schema as  } from "./main.d";

@jvanderen1
Copy link
Author

jvanderen1 commented Jan 4, 2022

@selfagency Are you using yarn? When I retried using yarn, the versions I got in my package.json were "nightly" and it worked. I believe there's apparent versioning incompatibilities between some parcel packages.

@mischnic
Copy link
Member

mischnic commented Jan 4, 2022

  • Using a strict 2.0.0-nightly.961 version range for all of Parcel packages doesn't result in compatible packages, because lerna somehow introduced some offsets between the versions during publishing.
  • Using a non-strict range is problematic in general, because even 2.0.0 is compatible with a caret nightly version range: https://jubianchi.github.io/semver-check/#/^2.0.0-nightly.961/2.0.0

For example these packages were all published at the same time:

 @parcel/config-webextension@2.0.2-nightly.2585
 parcel@2.0.0-nightly.961
 @parcel/transformer-xml@2.0.2-nightly.2585
 @parcel/transformer-yaml@2.0.0-nightly.963

@selfagency
Copy link

selfagency commented Jan 4, 2022

@jvanderen1 @mischnic I am using yarn and I switched from "^2.0.0-nightly.961" to "^2.0.0-nightly" and I'm still having the issue. You can try the repo here.

Also, how do I get the generated types file to inline my other types instead of importing them from my main.d.ts, which it's not even copying into the bundle?

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