Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Decide: `@Injectable` imported under an alias — ngtsc emits no `ɵfac`, OXC does

Cerrado
#507 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
angular, rust, typescript
Área
compilers

Línea de trabajo

Compare the alias case in the issue with ngtsc’s needsFactory logic in packages/compiler-cli/src/ngtsc/annotations/src/injectable.ts. Review the OXC output and decide whether to preserve its working factory or match ngtsc; if keeping OXC’s behavior, record the difference in napi/angular-compiler/e2e/compare/fixtures/known-differences.ts. Done means the behavior decision is reflected in the fixture list.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

question

With #504, OXC finds Angular class decorators by their @angular/core import, so an aliased @Injectable is now compiled. ngtsc 22.1.7 compiles it differently. It looks like an ngtsc bug. This issue records the difference and asks whether we keep OXC's output.

Repro

import {Injectable as X} from '@angular/core';
@X({providedIn: 'root'})
export class S {}

ngtsc 22.1.7

export class S {
    static ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: S, factory: S.ɵfac, providedIn: 'root' });
}
static ɵprov: i0.ɵɵInjectableDeclaration<any>;

No ɵfac and no setClassMetadata. ɵprov.factory points at S.ɵfac, which doesn't exist, so injecting S fails at runtime.

Cause, in packages/compiler-cli/src/ngtsc/annotations/src/injectable.ts:

needsFactory:
  meta.decorators === null ||
  decorators.every((current) => !isAngularCore(current) || current.name === 'Injectable'),

current.name is the name as written (X), so an aliased import gives needsFactory = false. setClassMetadata is only emitted inside if (analysis.needsFactory), so it is dropped too.

OXC (#504 tip)

export class S {
static ɵfac = /*@__PURE__*/ (() =>{
  let ɵS_BaseFactory;
  return function S_Factory(__ngFactoryType__) {
    return (ɵS_BaseFactory || (ɵS_BaseFactory = i0.ɵɵgetInheritedFactory(S)))((__ngFactoryType__ || S));
  };
})();
static ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({token:S,factory:S.ɵfac,providedIn:"root"});
}
// + ɵsetClassMetadata(S,[{type:X,args:[{providedIn:"root"}]}],null,null)
static ɵfac: i0.ɵɵFactoryDeclaration<S, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<S>;

On main the aliased decorator is not recognized at all, so the class is left as written (@X({providedIn: 'root'}) export class S {}).

Decision needed

  • Keep OXC's output (a working factory). This is a known difference from ngtsc. Add it to napi/angular-compiler/e2e/compare/fixtures/known-differences.ts.
  • Or copy ngtsc's output exactly. That gives a broken ɵprov.

Recommendation: keep it, record the difference, and maybe report it upstream.

Note: the ɵgetInheritedFactory form and InjectableDeclaration<S> vs <any> also show up for a plain @Injectable() class with no constructor, on main too. Not specific to the alias.

Lenguaje dominante
Rust
Estrellas
232
Forks
21
Merge medio
1 d 18 h
PR fusionados (30 d)
59

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

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de voidzero-dev/oxc-angular-compiler

Todos los issues de voidzero-dev/oxc-angular-compiler

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.