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

Add type for second return type when using Config.get #138

Open
2 of 4 tasks
bashleigh opened this issue Aug 14, 2019 · 2 comments
Open
2 of 4 tasks

Add type for second return type when using Config.get #138

bashleigh opened this issue Aug 14, 2019 · 2 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request

Comments

@bashleigh
Copy link
Collaborator

Issue type:

  • question
  • bug report
  • 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

@bashleigh bashleigh self-assigned this Aug 14, 2019
@bashleigh bashleigh added bug Something isn't working enhancement New feature or request labels Aug 14, 2019
@bashleigh
Copy link
Collaborator Author

Work around

config.get('swagger.version', 'beta') as string

@jeffminsungkim
Copy link
Contributor

@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');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants