nestjs-config
nestjs-config copied to clipboard
Add type for second return type when using Config.get
Issue type:
- [ ] question
- [x] bug report
- [x] feature request
- [ ] documentation issue
nestjs-config version
@nestjs/common+core or other package versions
- @nestjs/common:
- @nestjs/core:
Excepted behavior
I want to be able to use strict typing within my service. Using config.get<string>('something', 'something')
will mean type string | undefined
is used. Need to be able to specify default type like get<string, string>()
where get<T, U>(pattern: string, def?: U): T | U
Actual behavior or outcome (for issue)
Cannot compile because string | undefined
doesn't match string
Replication/Example
Work around
config.get('swagger.version', 'beta') as string
@bashleigh
Not quite sure what you're trying to approach, but here's what I came up with.
class ConfigService {
get<T, U = T | undefined | null>(param: T | T[], value: U): T | T[] | U {
// return something
}
}
const config = new ConfigService();
config.get<string>('hello', 'nestjs');