TemplateStringsArray could contain undefined and should always have index 0
See original GitHub issueBug Report
🔎 Search Terms
TemplateStringsArray undefined
🕗 Version & Regression Information
- This is a crash
- This changed between versions ______ and 4.4.4
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
- I was unable to test this on prior versions because _______
⏯ Playground Link
Playground link with relevant code 1
Playground link with relevant code 2
💻 Code
function fn (template :TemplateStringsArray) :string {
return template.raw[0];
}
function fn (template :TemplateStringsArray) :string {
return template[0];
}
🙁 Actual behavior
-
the first sample throw an error (when
"noUncheckedIndexedAccess": true
) -
the second sample doesn’t throw an error (when
"noUncheckedIndexedAccess": false
)
🙂 Expected behavior
- the first sample should never throw an error (because 0 index of
template.raw
will always be a string):
console.log``;// [ '' ]
- the second sample should always throw an error (because item of
template
could beundefined
):
console.log`\unknown`;// [ undefined ]
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
react-i18next translation is not working for passed on Prop ...
I will be making sure that always a product value is passed, not undefined or null. reactjs · typescript · i18next · react-i18next...
Read more >Documentation - Template Literal Types - TypeScript
Template literal types build on string literal types, and have the ability to expand into many strings via unions. They have the same...
Read more >TypeScript - react-i18next documentation
The keys and return type inference will not work, because TemplateStringsArray does not accept generic types yet. You can use Tagged Template Literal...
Read more >Object literal may only specify known properties in TS
The Employee type only has an id property, so when we try to assign a name ... make sure to type all of...
Read more >Module @sap-cloud-sdk/util
We do not consider if the generator is executed on windows or unix systems. It will always be \n to have consistent clients...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Here are the discussion in releated PR https://github.com/microsoft/TypeScript/pull/46826#pullrequestreview-810408126:
DanielRosenwasser:
LongTengDao:
sandersn:
This isn’t quite right; the linked PR uses the tuple type
[string, ...string[]]
which is capable of representing non-empty string arrays.