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

Can't append two string literal type values #18081

Closed
justinwoo opened this issue Aug 28, 2017 · 2 comments
Closed

Can't append two string literal type values #18081

justinwoo opened this issue Aug 28, 2017 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@justinwoo
Copy link

I'd like to append two const string literal values together and extract or assign a new string literal type.

Sorry if this is a duplicate of something, I couldn't find an existing issue.

TypeScript Version: 2.4.2 / PlayGround

Code

const APPLE = 'APPLE';
const PINEAPPLE = 'PINEAPPLE'

type AppleLiteralType = 'APPLE'
const APPLE2: AppleLiteralType = APPLE

// this is only `string`,
// even though it's two literals appended
const APPLEPINEAPPLE = APPLE + PINEAPPLE;

// Type 'string' is not assignable to type '"APPLEPINEAPPLE"'.
const Test: 'APPLEPINEAPPLE' = APPLE + PINEAPPLE;
const Test2: 'APPLEPINEAPPLE' = `${APPLE}${PINEAPPLE}`;

Expected behavior:
Test and/or Test2 should work with the `'APPLEPINEAPPLE' string literal type

Actual behavior:
Test and Test2 both turn into string types

@ikatyang
Copy link
Contributor

Duplicate of #12940 or #17512.

@justinwoo
Copy link
Author

Ahh, thanks!

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Aug 28, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants