Skip to content

Commit 2d2d7de

Browse files
committed
Rename strictOptionalProperties -> exactOptionalPropertyTypes and remove from strict family
1 parent d46d82c commit 2d2d7de

File tree

88 files changed

+751
-1373
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+751
-1373
lines changed

src/compiler/checker.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,12 @@ namespace ts {
343343
const strictFunctionTypes = getStrictOptionValue(compilerOptions, "strictFunctionTypes");
344344
const strictBindCallApply = getStrictOptionValue(compilerOptions, "strictBindCallApply");
345345
const strictPropertyInitialization = getStrictOptionValue(compilerOptions, "strictPropertyInitialization");
346-
const strictOptionalProperties = getStrictOptionValue(compilerOptions, "strictOptionalProperties");
347346
const noImplicitAny = getStrictOptionValue(compilerOptions, "noImplicitAny");
348347
const noImplicitThis = getStrictOptionValue(compilerOptions, "noImplicitThis");
349348
const useUnknownInCatchVariables = getStrictOptionValue(compilerOptions, "useUnknownInCatchVariables");
350349
const keyofStringsOnly = !!compilerOptions.keyofStringsOnly;
351350
const freshObjectLiteralFlag = compilerOptions.suppressExcessPropertyErrors ? 0 : ObjectFlags.FreshLiteral;
351+
const exactOptionalPropertyTypes = compilerOptions.exactOptionalPropertyTypes;
352352

353353
const checkBinaryExpression = createCheckBinaryExpression();
354354
const emitResolver = createResolver();
@@ -739,7 +739,7 @@ namespace ts {
739739
const undefinedType = createIntrinsicType(TypeFlags.Undefined, "undefined");
740740
const undefinedWideningType = strictNullChecks ? undefinedType : createIntrinsicType(TypeFlags.Undefined, "undefined", ObjectFlags.ContainsWideningType);
741741
const optionalType = createIntrinsicType(TypeFlags.Undefined, "undefined");
742-
const missingType = strictOptionalProperties ? createIntrinsicType(TypeFlags.Undefined, "undefined") : undefinedType;
742+
const missingType = exactOptionalPropertyTypes ? createIntrinsicType(TypeFlags.Undefined, "undefined") : undefinedType;
743743
const nullType = createIntrinsicType(TypeFlags.Null, "null");
744744
const nullWideningType = strictNullChecks ? nullType : createIntrinsicType(TypeFlags.Null, "null", ObjectFlags.ContainsWideningType);
745745
const stringType = createIntrinsicType(TypeFlags.String, "string");
@@ -13884,7 +13884,7 @@ namespace ts {
1388413884
if (includes & TypeFlags.AnyOrUnknown) {
1388513885
return includes & TypeFlags.Any ? includes & TypeFlags.IncludesWildcard ? wildcardType : anyType : unknownType;
1388613886
}
13887-
if (strictOptionalProperties && includes & TypeFlags.Undefined) {
13887+
if (exactOptionalPropertyTypes && includes & TypeFlags.Undefined) {
1388813888
const missingIndex = binarySearch(typeSet, missingType, getTypeId, compareValues);
1388913889
if (missingIndex >= 0 && containsType(typeSet, undefinedType)) {
1389013890
orderedRemoveItemAt(typeSet, missingIndex);
@@ -20356,15 +20356,15 @@ namespace ts {
2035620356
}
2035720357

2035820358
function removeMissingType(type: Type, isOptional: boolean) {
20359-
return strictOptionalProperties && isOptional ? removeType(type, missingType) : type;
20359+
return exactOptionalPropertyTypes && isOptional ? removeType(type, missingType) : type;
2036020360
}
2036120361

2036220362
function containsMissingType(type: Type) {
20363-
return strictOptionalProperties && (type === missingType || type.flags & TypeFlags.Union && containsType((type as UnionType).types, missingType));
20363+
return exactOptionalPropertyTypes && (type === missingType || type.flags & TypeFlags.Union && containsType((type as UnionType).types, missingType));
2036420364
}
2036520365

2036620366
function removeMissingOrUndefinedType(type: Type): Type {
20367-
return strictOptionalProperties ? removeType(type, missingType) : getTypeWithFacts(type, TypeFacts.NEUndefined);
20367+
return exactOptionalPropertyTypes ? removeType(type, missingType) : getTypeWithFacts(type, TypeFacts.NEUndefined);
2036820368
}
2036920369

2037020370
/**
@@ -21750,7 +21750,7 @@ namespace ts {
2175021750
}
2175121751

2175221752
function isTypeOrBaseIdenticalTo(s: Type, t: Type) {
21753-
return strictOptionalProperties && t === missingType ? s === t :
21753+
return exactOptionalPropertyTypes && t === missingType ? s === t :
2175421754
(isTypeIdenticalTo(s, t) || !!(t.flags & TypeFlags.String && s.flags & TypeFlags.StringLiteral || t.flags & TypeFlags.Number && s.flags & TypeFlags.NumberLiteral));
2175521755
}
2175621756

@@ -26079,7 +26079,7 @@ namespace ts {
2607926079
elementFlags.push(ElementFlags.Rest);
2608026080
}
2608126081
}
26082-
else if (strictOptionalProperties && e.kind === SyntaxKind.OmittedExpression) {
26082+
else if (exactOptionalPropertyTypes && e.kind === SyntaxKind.OmittedExpression) {
2608326083
hasOmittedExpression = true;
2608426084
elementTypes.push(missingType);
2608526085
elementFlags.push(ElementFlags.Optional);

src/compiler/commandLineParser.ts

+7-8
Original file line numberDiff line numberDiff line change
@@ -648,14 +648,6 @@ namespace ts {
648648
description: Diagnostics.Check_for_class_properties_that_are_declared_but_not_set_in_the_constructor,
649649
defaultValueDescription: Diagnostics.false_unless_strict_is_set
650650
},
651-
{
652-
name: "strictOptionalProperties",
653-
type: "boolean",
654-
affectsSemanticDiagnostics: true,
655-
strictFlag: true,
656-
category: Diagnostics.Type_Checking,
657-
description: Diagnostics.Enable_strict_checking_of_optional_properties
658-
},
659651
{
660652
name: "noImplicitThis",
661653
type: "boolean",
@@ -700,6 +692,13 @@ namespace ts {
700692
description: Diagnostics.Raise_an_error_when_a_function_parameter_isn_t_read,
701693
defaultValueDescription: "false"
702694
},
695+
{
696+
name: "exactOptionalPropertyTypes",
697+
type: "boolean",
698+
affectsSemanticDiagnostics: true,
699+
category: Diagnostics.Type_Checking,
700+
description: Diagnostics.Interpret_optional_property_types_as_written_rather_than_adding_undefined
701+
},
703702
{
704703
name: "noImplicitReturns",
705704
type: "boolean",

src/compiler/diagnosticMessages.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4853,7 +4853,7 @@
48534853
"category": "Message",
48544854
"code": 6242
48554855
},
4856-
"Enable strict checking of optional properties.": {
4856+
"Interpret optional property types as written, rather than adding 'undefined'.": {
48574857
"category": "Message",
48584858
"code": 6243
48594859
},

src/compiler/program.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3043,8 +3043,8 @@ namespace ts {
30433043
if (options.strictPropertyInitialization && !getStrictOptionValue(options, "strictNullChecks")) {
30443044
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "strictPropertyInitialization", "strictNullChecks");
30453045
}
3046-
if (options.strictOptionalProperties && !getStrictOptionValue(options, "strictNullChecks")) {
3047-
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "strictOptionalProperties", "strictNullChecks");
3046+
if (options.exactOptionalPropertyTypes && !getStrictOptionValue(options, "strictNullChecks")) {
3047+
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "exactOptionalPropertyTypes", "strictNullChecks");
30483048
}
30493049

30503050
if (options.isolatedModules) {

src/compiler/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5971,6 +5971,7 @@ namespace ts {
59715971
downlevelIteration?: boolean;
59725972
emitBOM?: boolean;
59735973
emitDecoratorMetadata?: boolean;
5974+
exactOptionalPropertyTypes?: boolean;
59745975
experimentalDecorators?: boolean;
59755976
forceConsistentCasingInFileNames?: boolean;
59765977
/*@internal*/generateCpuProfile?: string;
@@ -6045,7 +6046,6 @@ namespace ts {
60456046
strictBindCallApply?: boolean; // Always combine with strict property
60466047
strictNullChecks?: boolean; // Always combine with strict property
60476048
strictPropertyInitialization?: boolean; // Always combine with strict property
6048-
strictOptionalProperties?: boolean; // Always combine with strict property
60496049
stripInternal?: boolean;
60506050
suppressExcessPropertyErrors?: boolean;
60516051
suppressImplicitAnyIndexErrors?: boolean;

src/compiler/utilities.ts

-1
Original file line numberDiff line numberDiff line change
@@ -6086,7 +6086,6 @@ namespace ts {
60866086
| "strictFunctionTypes"
60876087
| "strictBindCallApply"
60886088
| "strictPropertyInitialization"
6089-
| "strictOptionalProperties"
60906089
| "alwaysStrict"
60916090
| "useUnknownInCatchVariables"
60926091
;

tests/baselines/reference/api/tsserverlibrary.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2853,6 +2853,7 @@ declare namespace ts {
28532853
downlevelIteration?: boolean;
28542854
emitBOM?: boolean;
28552855
emitDecoratorMetadata?: boolean;
2856+
exactOptionalPropertyTypes?: boolean;
28562857
experimentalDecorators?: boolean;
28572858
forceConsistentCasingInFileNames?: boolean;
28582859
importHelpers?: boolean;
@@ -2913,7 +2914,6 @@ declare namespace ts {
29132914
strictBindCallApply?: boolean;
29142915
strictNullChecks?: boolean;
29152916
strictPropertyInitialization?: boolean;
2916-
strictOptionalProperties?: boolean;
29172917
stripInternal?: boolean;
29182918
suppressExcessPropertyErrors?: boolean;
29192919
suppressImplicitAnyIndexErrors?: boolean;

tests/baselines/reference/api/typescript.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2853,6 +2853,7 @@ declare namespace ts {
28532853
downlevelIteration?: boolean;
28542854
emitBOM?: boolean;
28552855
emitDecoratorMetadata?: boolean;
2856+
exactOptionalPropertyTypes?: boolean;
28562857
experimentalDecorators?: boolean;
28572858
forceConsistentCasingInFileNames?: boolean;
28582859
importHelpers?: boolean;
@@ -2913,7 +2914,6 @@ declare namespace ts {
29132914
strictBindCallApply?: boolean;
29142915
strictNullChecks?: boolean;
29152916
strictPropertyInitialization?: boolean;
2916-
strictOptionalProperties?: boolean;
29172917
stripInternal?: boolean;
29182918
suppressExcessPropertyErrors?: boolean;
29192919
suppressImplicitAnyIndexErrors?: boolean;

tests/baselines/reference/checkJsxIntersectionElementPropsType.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ declare class Component<P> {
1616

1717
class C<T> extends Component<{ x?: boolean; } & T> {}
1818
>C : C<T>
19-
>Component : Component<{ x?: boolean; } & T>
19+
>Component : Component<{ x?: boolean | undefined; } & T>
2020
>x : boolean | undefined
2121

2222
const y = new C({foobar: "example"});

tests/baselines/reference/circularlyConstrainedMappedTypeContainingConditionalNoInfiniteInstantiationDepth.types

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ declare class Component<P> {
1010
>context : any
1111

1212
readonly props: Readonly<P> & Readonly<{ children?: {} }>;
13-
>props : Readonly<P> & Readonly<{ children?: {}; }>
13+
>props : Readonly<P> & Readonly<{ children?: {} | undefined; }>
1414
>children : {} | undefined
1515
}
1616
interface ComponentClass<P = {}> {
@@ -29,7 +29,7 @@ interface ComponentClass<P = {}> {
2929
}
3030
interface FunctionComponent<P = {}> {
3131
(props: P & { children?: {} }, context?: any): {} | null;
32-
>props : P & { children?: {}; }
32+
>props : P & { children?: {} | undefined; }
3333
>children : {} | undefined
3434
>context : any
3535
>null : null

tests/baselines/reference/contextuallyTypedParametersWithInitializers.types

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ declare function id3<T extends (x: { foo: any }) => any>(input: T): T;
1616

1717
declare function id4<T extends (x: { foo?: number }) => any>(input: T): T;
1818
>id4 : <T extends (x: { foo?: number;}) => any>(input: T) => T
19-
>x : { foo?: number; }
19+
>x : { foo?: number | undefined; }
2020
>foo : number | undefined
2121
>input : T
2222

@@ -60,10 +60,10 @@ const f13 = id3(function ({ foo = 42 }) { return foo });
6060
>foo : any
6161

6262
const f14 = id4(function ({ foo = 42 }) { return foo });
63-
>f14 : ({ foo }: { foo?: number; }) => number
64-
>id4(function ({ foo = 42 }) { return foo }) : ({ foo }: { foo?: number; }) => number
65-
>id4 : <T extends (x: { foo?: number; }) => any>(input: T) => T
66-
>function ({ foo = 42 }) { return foo } : ({ foo }: { foo?: number; }) => number
63+
>f14 : ({ foo }: { foo?: number | undefined; }) => number
64+
>id4(function ({ foo = 42 }) { return foo }) : ({ foo }: { foo?: number | undefined; }) => number
65+
>id4 : <T extends (x: { foo?: number | undefined; }) => any>(input: T) => T
66+
>function ({ foo = 42 }) { return foo } : ({ foo }: { foo?: number | undefined; }) => number
6767
>foo : number
6868
>42 : 42
6969
>foo : number

0 commit comments

Comments
 (0)