Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

@bem-react/classname: Unclear typing for element-bound class name formatters

Aperta
#636 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

@rrabmig ci sta già lavorando.

Dal 20/6/2026.

  • #637 di @rrabmig — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Refactoring
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
typescript
Ambito
frontend

Direzione di ricerca

Inizia individuando l’helper cn() e le dichiarazioni del tipo ClassNameFormatter in @bem-react/classname. Confronta le forme di creazione con un argomento e con due stringhe, introduci la tipizzazione distinta associata all’elemento descritta nell’issue e aggiungi o aggiorna i controlli TypeScript in modo che il passaggio di un secondo nome di elemento venga rifiutato, mentre le chiamate ai modifier rimangano valide.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Current behaviour:
The cn() helper can create a formatter in two different ways:

const cnBlock = cn('Block');
const cnBlockElement = cn('Block', 'Element');

Both values are currently typed as ClassNameFormatter, but the second form behaves differently and makes part of the callable API misleading.

/* block formatter*/
const cnBlock = cn('Block');

cnBlock('Element'); // => Block-Element

cnBlock('Element', { mod: true }); // => Block-Element Block-Element_mod

cnBlock({ mod: true }); // => Block Block_mod
/* element formatter*/
const cnBlockElement = cn('Block', 'Element');

cnBlockElement('Element2', { mod: true }); // => Block-Element Block-Element_mod

cnBlockElement({ mod: true }); // => Block-Element Block-Element_mod

Problem: the first argument 'Element2' in this call is accepted by types, but has no effect. This makes the type contract unclear. For an element-bound formatter, passing another element name is meaningless: the element is already fixed when the formatter is created and Block-Element-Element can't exist as well.

Suggestion: the two formatter creation patterns should have different return types:

ClassNameFormatter]= for block formatters created by the one-argument form
ClassNameElementFormatter- for element-bound formatters created by the two strings

cnBlockElement('Element2', { mod: true });
// should be a TypeScript error

Notes:

  • Not a runtime bug
  • Bump will be safe since first argument was doing nothing
  • I am ready to fix that
Lingua principale
TypeScript
Stelle
450
Fork
69
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di bem/bem-react

Tutte le issue di bem/bem-react

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.