vovaspace / brandi

The dependency injection container powered by TypeScript.
https://brandi.js.org
ISC License
193 stars 12 forks source link

Injected not working when disabled strictNullChecks #26

Open skrylnikov opened 2 years ago

skrylnikov commented 2 years ago

Injected not working when disabled strictNullChecks. Because injected expect optional token.

Example: https://www.typescriptlang.org/play?strictNullChecks=false#code/JYWwDg9gTgLgBAbzsAdgKwKYGMYYCYA0cMEA1hinAL5wBmUEIcA5AEZQCGKewzA3AFgAUMKwAbDgGdJcAIKIqw0ROlwAQomFw4WCCkkwoAVxzQAFGCjAAbh1xwOALjkBKBIqEfReg3AAqZBQyALyaQtpOxIEoADyyAHxmzBzMLgRacKzOJOSxaolsqemeSiJCqJg4+GZqRAG5kgB0HC6CZUA

import { injected, token } from 'brandi';

class A {}

class B {
  constructor(private a: A){}
}

const Tokens = {
  a: token<A>('a'),
  b: token<B>('b'),
}

injected(B, Tokens.a);

Error:

Argument of type 'Token<A>' is not assignable to parameter of type 'OptionalToken<A>'.
  Types of property '__o' are incompatible.
    Type 'false' is not assignable to type 'true'.
kormanowsky commented 1 year ago

Got the same bug, in v5.0.0. In v4.0.2 it works fine