如何使用Deno定义JSX.IntrinsicElements,使用nano_jsx?

huangapple go评论64阅读模式
英文:

How to define JSX.IntrinsicElements using nano_jsx with Deno?

问题

Here's the translation of the non-code parts:

如何解决这个错误?

> JSX元素隐式具有类型'any',因为不存在接口'JSX.IntrinsicElements'。deno-ts(7026)

这里是有问题的代码:

这是Deno文章中的示例代码:https://deno.com/blog/a-whole-website-in-a-single-js-file-continued

这是源代码:https://dash.deno.com/playground/website-in-a-single-js-2

英文:

How do I get rid of this error?

> JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.deno-ts(7026)

如何使用Deno定义JSX.IntrinsicElements,使用nano_jsx?

Here's the problematic code:

const problematicCode = <div>Hello world</div>

This is example code in this Deno article: https://deno.com/blog/a-whole-website-in-a-single-js-file-continued

Here's the source code: https://dash.deno.com/playground/website-in-a-single-js-2

答案1

得分: 0

For Nano JSX to declare the jsx type in a single file use:

/** @jsx h */
/** @jsxFrag Fragment */
import { h, Fragment } from "https://deno.land/x/nano_jsx@v0.0.37/mod.ts";

For Preact:

/** @jsx h */
/** @jsxFrag Fragment */
import { h, Fragment } from "https://esm.sh/preact@10.8.2";

Fresh uses the deno.json config with the preact import map like this:

"compilerOptions": {
  "jsx": "react-jsx",
  "jsxImportSource": "preact"
}
英文:

For Nano JSX to declare the jsx type in a single file use:

/** @jsx h */
/** @jsxFrag Fragment */
import { h, Fragment } from "https://deno.land/x/nano_jsx@v0.0.37/mod.ts";

For Preact:

/** @jsx h */
/** @jsxFrag Fragment */
import { h, Fragment } from "https://esm.sh/preact@10.8.2";

Fresh uses the deno.json config with the preact import map like this:

  "compilerOptions": {
    "jsx": "react-jsx",
    "jsxImportSource": "preact"
  }

huangapple
  • 本文由 发表于 2023年5月7日 07:24:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76191604.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定