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

Html Namespace not found in .tsx files #265

Open
2 tasks done
ashmortar opened this issue Aug 7, 2024 · 2 comments · May be fixed by #287
Open
2 tasks done

Html Namespace not found in .tsx files #265

ashmortar opened this issue Aug 7, 2024 · 2 comments · May be fixed by #287
Assignees

Comments

@ashmortar
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Versions

4.2.0, 4.2.1

Description

I am having this same issue for 4.2.0 and 4.2.1 using express and node in any tsx file in my project.

example:

type LinkProps = { class: string }  &
  (
    | {
        'hx-get': string;
      }
    | {
        href: string;
      }
  );

export function Link({
  class: className,
  children,
  ...rest
}: Html.PropsWithChildren<LinkProps>) {
  const props =
    `href` in rest
      ? { ...rest, target: '_blank', rel: 'noopener noreferrer' }
      : rest;
  const ourClass = className ? className : 'link';

  return (
    <a class={ourClass} {...props}>
      {children}
    </a>
  );
}

Error at Html reported by typescript:

Cannot find namespace 'Html'.ts(2503)
⚠ Error(TS2503)  | 
Cannot find namespace Html .

Error at {children}

Usage of xss-prone content without `safe` attribute. https://kitajs.github.io/ts-html-plugin#k601ts(0 K601)
⚠ Error
Usage of xss-prone content without `safe` attribute. https://kitajs.github.io/ts-html-plugin#k601
(parameter) children: Html.PropsWithChildren<LinkProps>

Steps to Reproduce

Create a project

mkdir nsamespace-bug
cd namespace-bug
touch index.tsx
touch tsconfig.json
npm init -y # ... your choices
npm i -E [email protected] @kitajs/[email protected] @kitajs/[email protected]
  • index.tsx
type LinkProps = { class: string } & (
  | {
      "hx-get": string;
    }
  | {
      href: string;
    }
);

export function Link({
  class: className,
  children,
  ...rest
}: Html.PropsWithChildren<LinkProps>) {
  const props =
    `href` in rest
      ? { ...rest, target: "_blank", rel: "noopener noreferrer" }
      : rest;
  const ourClass = className ? className : "link";

  return (
    <a class={ourClass} {...props}>
      {children}
    </a>
  );
}
  • tsconfig.json
{
  "compilerOptions": {
    "strict": true,
    "strictNullChecks": true,
    "module": "commonjs",
    "declaration": true,
    "allowSyntheticDefaultImports": true,
    "forceConsistentCasingInFileNames": true,
    "target": "ES2021",
    "outDir": "./dist",
    "baseUrl": "./",
    "skipLibCheck": true,
    "jsx": "react-jsx",
    "jsxImportSource": "@kitajs/html",
    "plugins": [{ "name": "@kitajs/ts-html-plugin" }]
  }
}

Expected Behavior

Namespace should be recognized in the file as it is if you install @kitajs/[email protected]

@arthurfiorette
Copy link
Member

arthurfiorette commented Aug 7, 2024

You need to manually import it if you want to use types.

@arthurfiorette arthurfiorette self-assigned this Aug 7, 2024
@arthurfiorette
Copy link
Member

I'll see what I can do to replicate 4.1.0 behavior's, but its a problem with current's typescript version and the register.d.ts file.

However I don't have enough time for now, are you able to start a PR?

@arthurfiorette arthurfiorette linked a pull request Sep 9, 2024 that will close this issue
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 a pull request may close this issue.

2 participants