Template files: expose template API types via a real import (drop tsconfig types requirement)
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 46/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- node.js, typescript
- Área
- developer-experience, tooling
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- TypeScript
- Estrellas
- 1.6k
- Forks
- 126
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de figma/code-connect
-
normalizePropName strips `#` characters from Figma property names instead of only the `#id` suffixAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
figma/code-connect#419 ·
-
feature request
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
figma/code-connect#403 ·
-
feature request
Dificultad 5/5 Más de una semana Aptitud para principiantes 38/100
figma/code-connect#414 ·
-
feature request
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
figma/code-connect#413 · 1 comentario ·
-
feature request
Dificultad 4/5 3-5 días Aptitud para principiantes 54/100
figma/code-connect#412 · 1 comentario ·
Todos los issues de figma/code-connect
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
jeanibarz/knowledge-base-mcp-server#1268 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 78/100
Koenkk/zigbee-herdsman-converters#13820 ·
Los mantenedores suelen responder en 2 días
-
A live recovery copy treats a large whole number and text with the same digits as the same valueAbiertobug sharing & sync
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
Los mantenedores suelen responder en 1 día
-
[prefer-expect-resolves] autofix leaves a stray ")" when the awaited expression is parenthesizedAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
jest-community/eslint-plugin-jest#2052 ·