You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Trying to figure something out and I found your documentation but it doesn't address my question. So I was hoping you could answer it and maybe update the docs.
I'm trying to narrow down a variable. My IDE (VS Code) understands that the variable is narrowed in the script (<script lang="ts">) but not in the "HTML" code outside of the script. Basically, I'm doing this inside of a component:
<script lang="ts">
// creating this as undefined so that the component can be created without passing in partner
export let partner: Partner | undefined = undefined;
if (! partner) {
partner = new Partner();
}
</script>
<span>{ partner.id }</span>
Inside of the script, after the if block, typescript accurately understands that partner is now Partner.
However, I get an error within the -- partner: Partner | undefined -- 'partner' is possibly 'undefined'.
My expectation is that since Partner has been narrowed at the end of the script block it'll be narrowed within the HTML as well.
Am I doing something wrong? Is there a workaround?
The text was updated successfully, but these errors were encountered:
Trying to figure something out and I found your documentation but it doesn't address my question. So I was hoping you could answer it and maybe update the docs.
I'm trying to narrow down a variable. My IDE (VS Code) understands that the variable is narrowed in the script (
<script lang="ts">
) but not in the "HTML" code outside of the script. Basically, I'm doing this inside of a component:Inside of the script, after the
if
block, typescript accurately understands that partner is nowPartner
.However, I get an error within the --
partner: Partner | undefined -- 'partner' is possibly 'undefined'
.My expectation is that since Partner has been narrowed at the end of the script block it'll be narrowed within the HTML as well.
Am I doing something wrong? Is there a workaround?
The text was updated successfully, but these errors were encountered: