Skip to content

Html Namespace not found in .tsx files  #265

@ashmortar

Description

@ashmortar

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]

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions