Template files: expose template API types via a real import (drop tsconfig types requirement)
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 46/100
- Issue 类型
- 功能
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- node.js, typescript
调研方向
Start by reading package.json and raw_templates.ts to understand the existing exports and how template imports are validated and rewritten. Then inspect the current figma-types declaration and its tests, if present, to see how the template API is typed. Done means the new subpath resolves through normal TypeScript module resolution and the CLI still rewrites it to the sandbox import while preserving existing 'figma' support.
由索引模型根据 Issue 内容生成。
描述
Related: #261 — that issue asks for the Template API types to be published via npm (which figma-types now does); this one asks to make them resolvable without tsconfig configuration.
Problem
Template files use a virtual module:
import figma from 'figma'
There is no figma package on npm — the module is injected by the CLI sandbox at execution time (raw_templates.ts rewrites the import to require('figma') before transpiling). TypeScript can therefore only resolve it through the ambient declaration shipped as @figma/code-connect/figma-types, which requires every consuming project to edit its tsconfig.json:
{ "compilerOptions": { "types": ["@figma/code-connect/figma-types"] } }
Pain points:
- Monorepos: one edit per package that owns Code Connect files (dozens for us).
- Packages that already set
compilerOptions.types(e.g. for@testing-library/jest-dom) must merge entries manually;@types/*auto-inclusion stops applying, so this is easy to get wrong. - The ambient
figma-typesentry also declares a globalrequire, which conflicts with@types/node— hence the need for the separatefigma-types-no-requirevariant.
Proposal
Let template files import the template API from a real module specifier, e.g.:
import figma from '@figma/code-connect/template'
Implementation sketch (sandbox semantics unchanged):
- New subpath export in
package.json:"./template": { "types": "./template.d.ts", "default": "./template.js" }template.d.ts: the currentfigma-typescontent expressed as a real module (export the API type / a typed default) instead ofdeclare module 'figma'.template.js: a stub that throws at runtime (e.g. "template files are executed by the Code Connect CLI") — it is never loaded in practice since the CLI rewrites the import.
- CLI: extend
figmaImportRegex/ import validation inraw_templates.tsto accept the new specifier alongside'figma', rewriting both torequire('figma')before transpilation. - Keep the existing
'figma'specifier +figma-typesfor backward compatibility.
Why a subpath and not the root entry: the root already exports a different figma (the React/HTML parser API — figma.connect, figma.boolean, …). The template API (selectedInstance, figma.code, figma.batch, figma.helpers) is a distinct surface.
Because the specifier becomes a real module, tsc/tsserver resolve its types through normal module resolution — no tsconfig changes needed in consuming projects.
Alternatives considered
@types/figmaon DefinitelyTyped: decouples the types from CLI releases (they must version in lockstep since they describe the template runtime API) and@typesauto-inclusion is disabled as soon as a project setscompilerOptions.types, which is common — so it wouldn't fix the main pain point.
- 主要语言
- TypeScript
- 星标
- 1.6k
- 派生
- 126
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
figma/code-connect 的其他 Issue
-
normalizePropName strips `#` characters from Figma property names instead of only the `#id` suffix未关闭
难度 2/5 1-3 小时 新手友好度 72/100
figma/code-connect#419 ·
-
feature request
难度 2/5 1-3 小时 新手友好度 66/100
figma/code-connect#403 ·
-
feature request
难度 5/5 一周以上 新手友好度 38/100
figma/code-connect#414 ·
-
feature request
难度 4/5 3-5 天 新手友好度 48/100
figma/code-connect#413 · 1 条评论 ·
-
feature request
难度 4/5 3-5 天 新手友好度 54/100
figma/code-connect#412 · 1 条评论 ·
查看 figma/code-connect 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
vercel-labs/ui#540 ·
维护者通常 1 天内回复
-
accepted ai-dev ai-implementing
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
-
Negative values skip k/M abbreviation and medium decimal format on line, stacked-area, and tooltip未关闭
难度 2/5 1-3 小时 新手友好度 84/100
britecharts/britecharts#1255 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 70/100
jeanibarz/knowledge-base-mcp-server#1268 ·
维护者通常 1 天内回复