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

Import JSX to avoid tsc namespace error #22

Merged
merged 2 commits into from
Jun 24, 2024
Merged

Import JSX to avoid tsc namespace error #22

merged 2 commits into from
Jun 24, 2024

Conversation

karlhorky
Copy link
Contributor

@karlhorky karlhorky commented Jun 24, 2024

To avoid type error with not being able to find JSX namespace

$ tsc

Error: node_modules/@nkzw/remdx/types.tsx(18,13): error TS2503: Cannot find namespace 'JSX'.
Error: node_modules/@nkzw/remdx/types.tsx(23,20): error TS2503: Cannot find namespace 'JSX'.

My original approach used the React global:

-JSX
+React.JSX

But there's already an import from 'react', so it seems simpler to add to that.

@karlhorky karlhorky changed the title Switch JSX to React.JSX Import JSX to avoid tsc namespace error Jun 24, 2024
@cpojer
Copy link
Collaborator

cpojer commented Jun 24, 2024

Huh, this is odd and shouldn't be necessary. What does your TypeScript config look like? Why are you type-checking node_modules?

@karlhorky
Copy link
Contributor Author

karlhorky commented Jun 24, 2024

tsconfig.json

{
  "$schema": "https://json.schemastore.org/tsconfig",
  "compilerOptions": {
    "lib": ["DOM", "DOM.Iterable", "ESNext"],
    "moduleDetection": "force",
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "isolatedModules": true,
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "downlevelIteration": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "noFallthroughCasesInSwitch": true,
    "skipLibCheck": true,
    "strict": true,
    "incremental": true,
    "noUncheckedIndexedAccess": true,
    "target": "ES2022",
    "module": "Node16",
    "moduleResolution": "Node16",
    "checkJs": true,
    "jsx": "preserve"
  },
  "include": [
    "remdx-env.d.ts",
    "**/*.ts",
    "**/*.tsx",
    "**/*.js",
    "**/*.jsx",
    "**/*.cjs",
    "**/*.mjs"
  ],
  "exclude": ["node_modules", "slideDecks/*/dist"]
}

remdx-env.d.ts (to get types for the *.re.mdx files)

/// <reference types="@nkzw/remdx/client.d.ts" />

@cpojer
Copy link
Collaborator

cpojer commented Jun 24, 2024

I tried this with a new ReMDX project and with your config, and this issue does not repro for me.

@karlhorky
Copy link
Contributor Author

karlhorky commented Jun 24, 2024

Hmm ok interesting, wonder if it has to do with us using the new types:

package.json

  "devDependencies": {
    "@types/react": "npm:types-react@19.0.0-rc.1",
    "@types/react-dom": "npm:types-react-dom@19.0.0",

Also, elsewhere in the monorepo I have this (I'm guessing it shouldn't affect this package, but maybe something is happening there):

tsconfig.json

"compilerOptions": {
  "jsxImportSource": "@emotion/react",

@karlhorky
Copy link
Contributor Author

@cpojer
Copy link
Collaborator

cpojer commented Jun 24, 2024

Ugh, that changes makes sense but is kinda annoying.

@cpojer cpojer merged commit 717c757 into nkzw-tech:main Jun 24, 2024
@cpojer
Copy link
Collaborator

cpojer commented Jun 24, 2024

Published as 0.14.1.

@karlhorky
Copy link
Contributor Author

Thanks!

@karlhorky karlhorky deleted the patch-2 branch June 24, 2024 14:08
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

Successfully merging this pull request may close these issues.

2 participants