-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
148 additions
and
22 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
tests/baselines/reference/controlFlowOptionalChain3.errors.txt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
controlFlowOptionalChain3.tsx(30,8): error TS18048: 'foo' is possibly 'undefined'. | ||
|
||
|
||
==== controlFlowOptionalChain3.tsx (1 errors) ==== | ||
/// <reference path="/.lib/react16.d.ts" /> | ||
|
||
// https://github.com/microsoft/TypeScript/issues/56482 | ||
|
||
import React from "react"; | ||
|
||
interface Foo { | ||
bar: boolean; | ||
} | ||
|
||
function test1(foo: Foo | undefined) { | ||
if (foo?.bar === false) { | ||
foo; | ||
} | ||
foo; | ||
} | ||
|
||
function test2(foo: Foo | undefined) { | ||
if (foo?.bar === false) { | ||
foo; | ||
} else { | ||
foo; | ||
} | ||
} | ||
|
||
function Test3({ foo }: { foo: Foo | undefined }) { | ||
return ( | ||
<div> | ||
{foo?.bar === false && "foo"} | ||
{foo.bar ? "true" : "false"} | ||
~~~ | ||
!!! error TS18048: 'foo' is possibly 'undefined'. | ||
</div> | ||
); | ||
} | ||
|
71 changes: 51 additions & 20 deletions
71
tests/baselines/reference/controlFlowOptionalChain3.symbols
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,79 @@ | ||
//// [tests/cases/conformance/controlFlow/controlFlowOptionalChain3.ts] //// | ||
//// [tests/cases/conformance/controlFlow/controlFlowOptionalChain3.tsx] //// | ||
|
||
=== controlFlowOptionalChain3.tsx === | ||
/// <reference path="react16.d.ts" /> | ||
|
||
=== controlFlowOptionalChain3.ts === | ||
// https://github.com/microsoft/TypeScript/issues/56482 | ||
|
||
import React from "react"; | ||
>React : Symbol(React, Decl(controlFlowOptionalChain3.tsx, 4, 6)) | ||
|
||
interface Foo { | ||
>Foo : Symbol(Foo, Decl(controlFlowOptionalChain3.ts, 0, 0)) | ||
>Foo : Symbol(Foo, Decl(controlFlowOptionalChain3.tsx, 4, 26)) | ||
|
||
bar: boolean; | ||
>bar : Symbol(Foo.bar, Decl(controlFlowOptionalChain3.ts, 2, 15)) | ||
>bar : Symbol(Foo.bar, Decl(controlFlowOptionalChain3.tsx, 6, 15)) | ||
} | ||
|
||
function test1(foo: Foo | undefined) { | ||
>test1 : Symbol(test1, Decl(controlFlowOptionalChain3.ts, 4, 1)) | ||
>foo : Symbol(foo, Decl(controlFlowOptionalChain3.ts, 6, 15)) | ||
>Foo : Symbol(Foo, Decl(controlFlowOptionalChain3.ts, 0, 0)) | ||
>test1 : Symbol(test1, Decl(controlFlowOptionalChain3.tsx, 8, 1)) | ||
>foo : Symbol(foo, Decl(controlFlowOptionalChain3.tsx, 10, 15)) | ||
>Foo : Symbol(Foo, Decl(controlFlowOptionalChain3.tsx, 4, 26)) | ||
|
||
if (foo?.bar === false) { | ||
>foo?.bar : Symbol(Foo.bar, Decl(controlFlowOptionalChain3.ts, 2, 15)) | ||
>foo : Symbol(foo, Decl(controlFlowOptionalChain3.ts, 6, 15)) | ||
>bar : Symbol(Foo.bar, Decl(controlFlowOptionalChain3.ts, 2, 15)) | ||
>foo?.bar : Symbol(Foo.bar, Decl(controlFlowOptionalChain3.tsx, 6, 15)) | ||
>foo : Symbol(foo, Decl(controlFlowOptionalChain3.tsx, 10, 15)) | ||
>bar : Symbol(Foo.bar, Decl(controlFlowOptionalChain3.tsx, 6, 15)) | ||
|
||
foo; | ||
>foo : Symbol(foo, Decl(controlFlowOptionalChain3.ts, 6, 15)) | ||
>foo : Symbol(foo, Decl(controlFlowOptionalChain3.tsx, 10, 15)) | ||
} | ||
foo; | ||
>foo : Symbol(foo, Decl(controlFlowOptionalChain3.ts, 6, 15)) | ||
>foo : Symbol(foo, Decl(controlFlowOptionalChain3.tsx, 10, 15)) | ||
} | ||
|
||
function test2(foo: Foo | undefined) { | ||
>test2 : Symbol(test2, Decl(controlFlowOptionalChain3.ts, 11, 1)) | ||
>foo : Symbol(foo, Decl(controlFlowOptionalChain3.ts, 13, 15)) | ||
>Foo : Symbol(Foo, Decl(controlFlowOptionalChain3.ts, 0, 0)) | ||
>test2 : Symbol(test2, Decl(controlFlowOptionalChain3.tsx, 15, 1)) | ||
>foo : Symbol(foo, Decl(controlFlowOptionalChain3.tsx, 17, 15)) | ||
>Foo : Symbol(Foo, Decl(controlFlowOptionalChain3.tsx, 4, 26)) | ||
|
||
if (foo?.bar === false) { | ||
>foo?.bar : Symbol(Foo.bar, Decl(controlFlowOptionalChain3.ts, 2, 15)) | ||
>foo : Symbol(foo, Decl(controlFlowOptionalChain3.ts, 13, 15)) | ||
>bar : Symbol(Foo.bar, Decl(controlFlowOptionalChain3.ts, 2, 15)) | ||
>foo?.bar : Symbol(Foo.bar, Decl(controlFlowOptionalChain3.tsx, 6, 15)) | ||
>foo : Symbol(foo, Decl(controlFlowOptionalChain3.tsx, 17, 15)) | ||
>bar : Symbol(Foo.bar, Decl(controlFlowOptionalChain3.tsx, 6, 15)) | ||
|
||
foo; | ||
>foo : Symbol(foo, Decl(controlFlowOptionalChain3.ts, 13, 15)) | ||
>foo : Symbol(foo, Decl(controlFlowOptionalChain3.tsx, 17, 15)) | ||
|
||
} else { | ||
foo; | ||
>foo : Symbol(foo, Decl(controlFlowOptionalChain3.ts, 13, 15)) | ||
>foo : Symbol(foo, Decl(controlFlowOptionalChain3.tsx, 17, 15)) | ||
} | ||
} | ||
|
||
function Test3({ foo }: { foo: Foo | undefined }) { | ||
>Test3 : Symbol(Test3, Decl(controlFlowOptionalChain3.tsx, 23, 1)) | ||
>foo : Symbol(foo, Decl(controlFlowOptionalChain3.tsx, 25, 16)) | ||
>foo : Symbol(foo, Decl(controlFlowOptionalChain3.tsx, 25, 25)) | ||
>Foo : Symbol(Foo, Decl(controlFlowOptionalChain3.tsx, 4, 26)) | ||
|
||
return ( | ||
<div> | ||
>div : Symbol(JSX.IntrinsicElements.div, Decl(react16.d.ts, 2546, 114)) | ||
|
||
{foo?.bar === false && "foo"} | ||
>foo?.bar : Symbol(Foo.bar, Decl(controlFlowOptionalChain3.tsx, 6, 15)) | ||
>foo : Symbol(foo, Decl(controlFlowOptionalChain3.tsx, 25, 16)) | ||
>bar : Symbol(Foo.bar, Decl(controlFlowOptionalChain3.tsx, 6, 15)) | ||
|
||
{foo.bar ? "true" : "false"} | ||
>foo.bar : Symbol(Foo.bar, Decl(controlFlowOptionalChain3.tsx, 6, 15)) | ||
>foo : Symbol(foo, Decl(controlFlowOptionalChain3.tsx, 25, 16)) | ||
>bar : Symbol(Foo.bar, Decl(controlFlowOptionalChain3.tsx, 6, 15)) | ||
|
||
</div> | ||
>div : Symbol(JSX.IntrinsicElements.div, Decl(react16.d.ts, 2546, 114)) | ||
|
||
); | ||
} | ||
|
This file contains 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
This file contains 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