Skip to content

Commit

Permalink
add another extra test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist committed Nov 22, 2023
1 parent b549581 commit c2b785e
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tests/baselines/reference/controlFlowOptionalChain3.errors.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
controlFlowOptionalChain3.tsx(30,8): error TS18048: 'foo' is possibly 'undefined'.
controlFlowOptionalChain3.tsx(36,31): error TS18048: 'options' is possibly 'undefined'.


==== controlFlowOptionalChain3.tsx (1 errors) ====
==== controlFlowOptionalChain3.tsx (2 errors) ====
/// <reference path="/.lib/react16.d.ts" />

// https://github.com/microsoft/TypeScript/issues/56482
Expand Down Expand Up @@ -37,4 +38,12 @@ controlFlowOptionalChain3.tsx(30,8): error TS18048: 'foo' is possibly 'undefined
</div>
);
}

function test4(options?: { a?: boolean; b?: boolean }) {
if (options?.a === false || options.b) {
~~~~~~~
!!! error TS18048: 'options' is possibly 'undefined'.
options;
}
}

19 changes: 19 additions & 0 deletions tests/baselines/reference/controlFlowOptionalChain3.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,22 @@ function Test3({ foo }: { foo: Foo | undefined }) {
);
}

function test4(options?: { a?: boolean; b?: boolean }) {
>test4 : Symbol(test4, Decl(controlFlowOptionalChain3.tsx, 32, 1))
>options : Symbol(options, Decl(controlFlowOptionalChain3.tsx, 34, 15))
>a : Symbol(a, Decl(controlFlowOptionalChain3.tsx, 34, 26))
>b : Symbol(b, Decl(controlFlowOptionalChain3.tsx, 34, 39))

if (options?.a === false || options.b) {
>options?.a : Symbol(a, Decl(controlFlowOptionalChain3.tsx, 34, 26))
>options : Symbol(options, Decl(controlFlowOptionalChain3.tsx, 34, 15))
>a : Symbol(a, Decl(controlFlowOptionalChain3.tsx, 34, 26))
>options.b : Symbol(b, Decl(controlFlowOptionalChain3.tsx, 34, 39))
>options : Symbol(options, Decl(controlFlowOptionalChain3.tsx, 34, 15))
>b : Symbol(b, Decl(controlFlowOptionalChain3.tsx, 34, 39))

options;
>options : Symbol(options, Decl(controlFlowOptionalChain3.tsx, 34, 15))
}
}

22 changes: 22 additions & 0 deletions tests/baselines/reference/controlFlowOptionalChain3.types
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,25 @@ function Test3({ foo }: { foo: Foo | undefined }) {
);
}

function test4(options?: { a?: boolean; b?: boolean }) {
>test4 : (options?: { a?: boolean; b?: boolean;}) => void
>options : { a?: boolean | undefined; b?: boolean | undefined; } | undefined
>a : boolean | undefined
>b : boolean | undefined

if (options?.a === false || options.b) {
>options?.a === false || options.b : boolean | undefined
>options?.a === false : boolean
>options?.a : boolean | undefined
>options : { a?: boolean | undefined; b?: boolean | undefined; } | undefined
>a : boolean | undefined
>false : false
>options.b : boolean | undefined
>options : { a?: boolean | undefined; b?: boolean | undefined; } | undefined
>b : boolean | undefined

options;
>options : { a?: boolean | undefined; b?: boolean | undefined; } | undefined
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,9 @@ function Test3({ foo }: { foo: Foo | undefined }) {
</div>
);
}

function test4(options?: { a?: boolean; b?: boolean }) {
if (options?.a === false || options.b) {
options;
}
}

0 comments on commit c2b785e

Please # to comment.