Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11235,7 +11235,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return baseTypeVariable ? getIntersectionType([type, baseTypeVariable]) : type;
}
else {
return strictNullChecks && symbol.flags & SymbolFlags.Optional ? getOptionalType(type) : type;
return strictNullChecks && symbol.flags & SymbolFlags.Optional ? getOptionalType(type, /*isProperty*/ true) : type;
Copy link
Member

@jakebailey jakebailey Feb 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm honestly really suspicious of every other call to this function now; I went and made isProperty required and about half of the callers are actually working with things that are explicitly property types (and so likely need to also pass true).

No tests change when I make everyone pass in this parameter, though, which makes me think that we don't have enough coverage of this particular option.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This option has a default though - did you try passing true to all calls of this function?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I mean I changed it from isProperty = false to isProperty: boolean and then examined all of the places where it error'd.

Not that this is directly required for this PR, just something I noticed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The missingType thing is only relevant here for with exactOptionalPropertyTypes - and that's not the most popular compiler option. So I definitely wouldn't be surprised if the test suite wouldn't be that comprehensive in this regard.

}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
=== tests/cases/compiler/stripMembersOptionality.ts ===
// repro from #52494

declare const someVal: Required<{
>someVal : Symbol(someVal, Decl(stripMembersOptionality.ts, 2, 13))
>Required : Symbol(Required, Decl(lib.es5.d.ts, --, --))

fn?(key: string): string | null;
>fn : Symbol(fn, Decl(stripMembersOptionality.ts, 2, 33))
>key : Symbol(key, Decl(stripMembersOptionality.ts, 3, 8))

}>;
someVal.fn("");
>someVal.fn : Symbol(fn, Decl(stripMembersOptionality.ts, 2, 33))
>someVal : Symbol(someVal, Decl(stripMembersOptionality.ts, 2, 13))
>fn : Symbol(fn, Decl(stripMembersOptionality.ts, 2, 33))

declare const someVal2: Required<{
>someVal2 : Symbol(someVal2, Decl(stripMembersOptionality.ts, 7, 13))
>Required : Symbol(Required, Decl(lib.es5.d.ts, --, --))

fn?: (key: string) => string | null;
>fn : Symbol(fn, Decl(stripMembersOptionality.ts, 7, 34))
>key : Symbol(key, Decl(stripMembersOptionality.ts, 8, 10))

}>;
someVal2.fn("");
>someVal2.fn : Symbol(fn, Decl(stripMembersOptionality.ts, 7, 34))
>someVal2 : Symbol(someVal2, Decl(stripMembersOptionality.ts, 7, 13))
>fn : Symbol(fn, Decl(stripMembersOptionality.ts, 7, 34))

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
=== tests/cases/compiler/stripMembersOptionality.ts ===
// repro from #52494

declare const someVal: Required<{
>someVal : Required<{ fn?(key: string): string | null; }>

fn?(key: string): string | null;
>fn : ((key: string) => string | null) | undefined
>key : string
>null : null

}>;
someVal.fn("");
>someVal.fn("") : string | null
>someVal.fn : (key: string) => string | null
>someVal : Required<{ fn?(key: string): string | null; }>
>fn : (key: string) => string | null
>"" : ""

declare const someVal2: Required<{
>someVal2 : Required<{ fn?: ((key: string) => string | null) | undefined; }>

fn?: (key: string) => string | null;
>fn : ((key: string) => string | null) | undefined
>key : string
>null : null

}>;
someVal2.fn("");
>someVal2.fn("") : string | null
>someVal2.fn : (key: string) => string | null
>someVal2 : Required<{ fn?: ((key: string) => string | null) | undefined; }>
>fn : (key: string) => string | null
>"" : ""

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
=== tests/cases/compiler/stripMembersOptionality.ts ===
// repro from #52494

declare const someVal: Required<{
>someVal : Symbol(someVal, Decl(stripMembersOptionality.ts, 2, 13))
>Required : Symbol(Required, Decl(lib.es5.d.ts, --, --))

fn?(key: string): string | null;
>fn : Symbol(fn, Decl(stripMembersOptionality.ts, 2, 33))
>key : Symbol(key, Decl(stripMembersOptionality.ts, 3, 8))

}>;
someVal.fn("");
>someVal.fn : Symbol(fn, Decl(stripMembersOptionality.ts, 2, 33))
>someVal : Symbol(someVal, Decl(stripMembersOptionality.ts, 2, 13))
>fn : Symbol(fn, Decl(stripMembersOptionality.ts, 2, 33))

declare const someVal2: Required<{
>someVal2 : Symbol(someVal2, Decl(stripMembersOptionality.ts, 7, 13))
>Required : Symbol(Required, Decl(lib.es5.d.ts, --, --))

fn?: (key: string) => string | null;
>fn : Symbol(fn, Decl(stripMembersOptionality.ts, 7, 34))
>key : Symbol(key, Decl(stripMembersOptionality.ts, 8, 10))

}>;
someVal2.fn("");
>someVal2.fn : Symbol(fn, Decl(stripMembersOptionality.ts, 7, 34))
>someVal2 : Symbol(someVal2, Decl(stripMembersOptionality.ts, 7, 13))
>fn : Symbol(fn, Decl(stripMembersOptionality.ts, 7, 34))

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
=== tests/cases/compiler/stripMembersOptionality.ts ===
// repro from #52494

declare const someVal: Required<{
>someVal : Required<{ fn?(key: string): string | null; }>

fn?(key: string): string | null;
>fn : ((key: string) => string | null) | undefined
>key : string
>null : null

}>;
someVal.fn("");
>someVal.fn("") : string | null
>someVal.fn : (key: string) => string | null
>someVal : Required<{ fn?(key: string): string | null; }>
>fn : (key: string) => string | null
>"" : ""

declare const someVal2: Required<{
>someVal2 : Required<{ fn?: (key: string) => string | null; }>

fn?: (key: string) => string | null;
>fn : ((key: string) => string | null) | undefined
>key : string
>null : null

}>;
someVal2.fn("");
>someVal2.fn("") : string | null
>someVal2.fn : (key: string) => string | null
>someVal2 : Required<{ fn?: (key: string) => string | null; }>
>fn : (key: string) => string | null
>"" : ""

15 changes: 15 additions & 0 deletions tests/cases/compiler/stripMembersOptionality.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// @strict: true
// @exactOptionalPropertyTypes: true, false
// @noEmit: true

// repro from #52494

declare const someVal: Required<{
fn?(key: string): string | null;
}>;
someVal.fn("");

declare const someVal2: Required<{
fn?: (key: string) => string | null;
}>;
someVal2.fn("");