Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConfigService::get is not type-hinting correctly its return value #573

Closed
ericmorand opened this issue May 21, 2021 · 4 comments
Closed

Comments

@ericmorand
Copy link

Consider the following use case:

const configuration = new ConfigService<{
    FOO: number
}<();

const foo = configuration.get('FOO');

foo?.bar; // should fail; doesn't because foo is inferred as any | undefined

It is expected that foo is resolved by TypeScript type checker as a number. But it is actually resolved as any | undefined.

get should have the following signature:

    get<P extends keyof K>(propertyPath: P): K[P];
@kamilmysliwiec
Copy link
Member

In the next major release, we'll add the infer option allowing you to auto infer type (including cases when the dot notation is used, which is awesome), PR here #493. We couldn't really infer types by default due to backward compatibility

@ericmorand
Copy link
Author

This V8 sounds so promising!!!

@ealionel
Copy link

ealionel commented Aug 30, 2021

In the next major release, we'll add the infer option allowing you to auto infer type (including cases when the dot notation is used, which is awesome), PR here #493. We couldn't really infer types by default due to backward compatibility

Maybe can we add a defaultInfer property in the ConfigModule.forRoot so it doesn't break backward compatiblity?

ConfigModule.forRoot({
  defaultInfer: true
})

@kamilmysliwiec
Copy link
Member

Type inference cannot be controlled by setting flags in the configuration as it doesn't happen at runtime

@nestjs nestjs locked and limited conversation to collaborators Aug 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants