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

Feature request: store constants for different build configurations #5376

Closed
stepancar opened this issue Oct 23, 2015 · 4 comments
Closed

Feature request: store constants for different build configurations #5376

stepancar opened this issue Oct 23, 2015 · 4 comments
Labels
Out of Scope This idea sits outside of the TypeScript language design constraints Suggestion An idea for TypeScript

Comments

@stepancar
Copy link

ASP.Net developers stores global constants in web.config. For different build configurations (Like Test, Debug, Release etc) they have different constants.
They have possibility to get constant by string key, and don't have possibily to chek existence of constant on development-time.

So, I have ts project, and want use different const , for example billingHost in different configurations

Test: test.billing.com
Debug: debug.billing.com
Release: billing.com

What i can do? i can define all constants in common module, and on run-time firstly substitute needed
constants values by configuration values, and then import this constants to consume modules.
I faced problem. I don't want another developers know about what test, debug constants i use.

I think constant should be generated on build-time.
Now I store constants in tsconfig.json

"consts": {
        "comments": "Here you can find your application constants",
        "emails": {
            "comments": "emails for different configurations",
            "sellerEmail": {
                "comments": "seller email, if you testing your app don't use original email!!!",
                "release": "seller@mail.com",
                "debug": "myDebugSeller@mail.com",
                "test": "myTestSeller@mail.com"
            }
        },
        "apiKeys": {
            "comments": "api keys for different configurations",
            "googleMapsApiKey": {
                "comments": "Use another key for testing you google maps, because its very expensive",
                "release": "asd!22asdjk_eweqwerqw",
                "debug": "werwqj!2324324",
                "test": "rwer334225_3423n"
            }
        }
    }

And on build-time i generate ts file which contains constants.
I have autocomple in consume files, and another developers can't see my test constants.
All constants stored in one file. Each team member (not necessary developer can change constant in config)

example of usage
try

May be we should investigate integration of this approach to typescript ecosystem?
For example add consts section to tsconfig + build configuration, and provide to compilation context needed consts?
Thank you!

@stepancar
Copy link
Author

@mhegazy, could you set any label for this issue? Maybe i should provide more info?

@mhegazy
Copy link
Contributor

mhegazy commented Oct 30, 2015

Sorry for the delay. I think i typed up the response but never hit the comment button..

So tsconfig.json is meant to be extensible. so adding additional properties there that you are using in a different tool is a fine proposition. and looks like you are already setup that generates the code you want.

Now, should the typescript compiler be aware of these properties and generate code for them on the fly, i would say no. I do not think this specific scenario is general enough to warrant being part of the compiler naively. if we can find more scenarios to support this then yes.

I think the core issue here is the lack of conditional compilation support (#3538), solving this would solve this issue as well as others.

@mhegazy mhegazy closed this as completed Oct 30, 2015
@mhegazy mhegazy reopened this Oct 30, 2015
@mhegazy mhegazy added Suggestion An idea for TypeScript Out of Scope This idea sits outside of the TypeScript language design constraints labels Oct 30, 2015
@stepancar
Copy link
Author

@mhegazy , thank you. Conditional compilation is what we realy need.

@mhegazy
Copy link
Contributor

mhegazy commented Nov 7, 2015

thanks for the reply. closing this ticket.

@mhegazy mhegazy closed this as completed Nov 7, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Out of Scope This idea sits outside of the TypeScript language design constraints Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants