Omit tostring from template literal spans if they are strings#948
Merged
Perryvw merged 3 commits intoTypeScriptToLua:masterfrom Dec 21, 2020
Merged
Omit tostring from template literal spans if they are strings#948Perryvw merged 3 commits intoTypeScriptToLua:masterfrom
Perryvw merged 3 commits intoTypeScriptToLua:masterfrom
Conversation
lolleko
requested changes
Dec 20, 2020
test/unit/templateLiterals.spec.ts
Outdated
| ["string | any", true], | ||
| ])("template span expect tostring for type (%p) - %p", (type, expectToString) => { | ||
| util.testFunction` | ||
| function func(msg: ${type}) { |
Member
There was a problem hiding this comment.
Can this be simplified to something like this?
let msg: ${type} ;
// @ts-ignore
return \`\${msg}\`;
Contributor
Author
There was a problem hiding this comment.
Somewhat, TypeScript is a bit too smart for that case
let msg: string | number = 5;
msg; // type: numberBut this gets around it
let msg = 5 as string | number;
msg; // type: string | number
test/unit/templateLiterals.spec.ts
Outdated
| // @ts-ignore | ||
| return func(""); | ||
| ` | ||
| .tap(builder => { |
Member
There was a problem hiding this comment.
I would prefer one test case for contains "tostring" and one test case for does not contain "tostring". That will result in a small amount of code duplication, but is a lot easier to read imo.
lolleko
approved these changes
Dec 21, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #940
Seems like a straight forward fix
Using the existing
isStringTypeto determine if the type is a string