diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9740d82d21460..2e8f0ff2ae692 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5915,9 +5915,6 @@ namespace ts { if (parameterDeclaration && isRequiredInitializedParameter(parameterDeclaration)) { parameterType = getOptionalType(parameterType); } - if ((context.flags & NodeBuilderFlags.NoUndefinedOptionalParameterType) && parameterDeclaration && !isJSDocParameterTag(parameterDeclaration) && isOptionalUninitializedParameter(parameterDeclaration)) { - parameterType = getTypeWithFacts(parameterType, TypeFacts.NEUndefined); - } const parameterTypeNode = serializeTypeForDeclaration(context, parameterType, parameterSymbol, context.enclosingDeclaration, privateSymbolVisitor, bundledImports); const modifiers = !(context.flags & NodeBuilderFlags.OmitParameterModifiers) && preserveModifierFlags && parameterDeclaration && parameterDeclaration.modifiers ? parameterDeclaration.modifiers.map(factory.cloneNode) : undefined; @@ -6544,7 +6541,7 @@ namespace ts { if (declWithExistingAnnotation && !isFunctionLikeDeclaration(declWithExistingAnnotation) && !isGetAccessorDeclaration(declWithExistingAnnotation)) { // try to reuse the existing annotation const existing = getEffectiveTypeAnnotationNode(declWithExistingAnnotation)!; - if (getTypeFromTypeNode(existing) === type && existingTypeNodeIsNotReferenceOrIsReferenceWithCompatibleTypeArgumentCount(existing, type)) { + if (typeNodeIsEquivalentToType(existing, declWithExistingAnnotation, type) && existingTypeNodeIsNotReferenceOrIsReferenceWithCompatibleTypeArgumentCount(existing, type)) { const result = serializeExistingTypeNode(context, existing, includePrivateSymbol, bundled); if (result) { return result; @@ -6562,6 +6559,17 @@ namespace ts { return result; } + function typeNodeIsEquivalentToType(typeNode: TypeNode, annotatedDeclaration: Declaration, type: Type) { + const typeFromTypeNode = getTypeFromTypeNode(typeNode); + if (typeFromTypeNode === type) { + return true; + } + if (isParameter(annotatedDeclaration) && annotatedDeclaration.questionToken) { + return getTypeWithFacts(type, TypeFacts.NEUndefined) === typeFromTypeNode; + } + return false; + } + function serializeReturnTypeForSignature(context: NodeBuilderContext, type: Type, signature: Signature, includePrivateSymbol?: (s: Symbol) => void, bundled?: boolean) { if (!isErrorType(type) && context.enclosingDeclaration) { const annotation = signature.declaration && getEffectiveReturnTypeNode(signature.declaration); @@ -42579,12 +42587,6 @@ namespace ts { hasSyntacticModifier(parameter, ModifierFlags.ParameterPropertyModifier); } - function isOptionalUninitializedParameter(parameter: ParameterDeclaration) { - return !!strictNullChecks && - isOptionalParameter(parameter) && - !parameter.initializer; - } - function isExpandoFunctionDeclaration(node: Declaration): boolean { const declaration = getParseTreeNode(node, isFunctionDeclaration); if (!declaration) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 9ae7d10b07cea..0831da97a629c 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4490,7 +4490,6 @@ namespace ts { UseAliasDefinedOutsideCurrentScope = 1 << 14, // Allow non-visible aliases UseSingleQuotesForStringLiteralType = 1 << 28, // Use single quotes for string literal type NoTypeReduction = 1 << 29, // Don't call getReducedType - NoUndefinedOptionalParameterType = 1 << 30, // Do not add undefined to optional parameter type // Error handling AllowThisInObjectLiteral = 1 << 15, diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 3b303c65eb83f..ca7155c30cacd 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -7659,4 +7659,8 @@ namespace ts { return state > States.NodeModules ? { topLevelNodeModulesIndex, topLevelPackageNameIndex, packageRootIndex, fileNameIndex } : undefined; } + + export function getParameterTypeNode(parameter: ParameterDeclaration | JSDocParameterTag) { + return parameter.kind === SyntaxKind.JSDocParameterTag ? parameter.typeExpression?.type : parameter.type; + } } diff --git a/src/services/codefixes/helpers.ts b/src/services/codefixes/helpers.ts index a33fe54ec2a7f..28fccba8190e3 100644 --- a/src/services/codefixes/helpers.ts +++ b/src/services/codefixes/helpers.ts @@ -194,7 +194,6 @@ namespace ts.codefix { const scriptTarget = getEmitScriptTarget(program.getCompilerOptions()); const flags = NodeBuilderFlags.NoTruncation - | NodeBuilderFlags.NoUndefinedOptionalParameterType | NodeBuilderFlags.SuppressAnyReturnType | NodeBuilderFlags.AllowEmptyTuple | (quotePreference === QuotePreference.Single ? NodeBuilderFlags.UseSingleQuotesForStringLiteralType : NodeBuilderFlags.None); diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 9ea997539f55f..6146af8bb9f75 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -2394,7 +2394,6 @@ declare namespace ts { UseAliasDefinedOutsideCurrentScope = 16384, UseSingleQuotesForStringLiteralType = 268435456, NoTypeReduction = 536870912, - NoUndefinedOptionalParameterType = 1073741824, AllowThisInObjectLiteral = 32768, AllowQualifiedNameInPlaceOfIdentifier = 65536, /** @deprecated AllowQualifedNameInPlaceOfIdentifier. Use AllowQualifiedNameInPlaceOfIdentifier instead. */ diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 45eed1b64845b..22af7579a0367 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -2394,7 +2394,6 @@ declare namespace ts { UseAliasDefinedOutsideCurrentScope = 16384, UseSingleQuotesForStringLiteralType = 268435456, NoTypeReduction = 536870912, - NoUndefinedOptionalParameterType = 1073741824, AllowThisInObjectLiteral = 32768, AllowQualifiedNameInPlaceOfIdentifier = 65536, /** @deprecated AllowQualifedNameInPlaceOfIdentifier. Use AllowQualifiedNameInPlaceOfIdentifier instead. */ diff --git a/tests/baselines/reference/arrayFakeFlatNoCrashInferenceDeclarations.types b/tests/baselines/reference/arrayFakeFlatNoCrashInferenceDeclarations.types index fd8dccc975c77..692e007dd92ba 100644 --- a/tests/baselines/reference/arrayFakeFlatNoCrashInferenceDeclarations.types +++ b/tests/baselines/reference/arrayFakeFlatNoCrashInferenceDeclarations.types @@ -19,7 +19,7 @@ type BadFlatArray = {obj: { >1 : 1 declare function flat( ->flat : (arr: A, depth?: D | undefined) => BadFlatArray[] +>flat : (arr: A, depth?: D) => BadFlatArray[] arr: A, >arr : A diff --git a/tests/baselines/reference/assertionTypePredicates1.types b/tests/baselines/reference/assertionTypePredicates1.types index e72b3077c9b95..064cf6066f4dd 100644 --- a/tests/baselines/reference/assertionTypePredicates1.types +++ b/tests/baselines/reference/assertionTypePredicates1.types @@ -270,7 +270,7 @@ namespace Debug { >Debug : typeof Debug export declare function assert(value: unknown, message?: string): asserts value; ->assert : (value: unknown, message?: string | undefined) => asserts value +>assert : (value: unknown, message?: string) => asserts value >value : unknown >message : string | undefined diff --git a/tests/baselines/reference/asyncFunctionsAndStrictNullChecks.types b/tests/baselines/reference/asyncFunctionsAndStrictNullChecks.types index 33ccf9c331fcc..f67fe49a61fb0 100644 --- a/tests/baselines/reference/asyncFunctionsAndStrictNullChecks.types +++ b/tests/baselines/reference/asyncFunctionsAndStrictNullChecks.types @@ -75,7 +75,7 @@ declare function resolve2(value: T): Windows.Foundation.IPromise; >Foundation : any async function sample2(x?: number) { ->sample2 : (x?: number | undefined) => Promise +>sample2 : (x?: number) => Promise >x : number | undefined let x1 = await resolve1(x); diff --git a/tests/baselines/reference/callsOnComplexSignatures.types b/tests/baselines/reference/callsOnComplexSignatures.types index a255300662666..192c64474400f 100644 --- a/tests/baselines/reference/callsOnComplexSignatures.types +++ b/tests/baselines/reference/callsOnComplexSignatures.types @@ -110,7 +110,7 @@ function test3(items: string[] | number[]) { } function test4( ->test4 : (arg1: ((...objs: { x: number;}[]) => number) | ((...objs: { y: number;}[]) => number), arg2: ((a: { x: number;}, b: object) => number) | ((a: object, b: { x: number;}) => number), arg3: ((a: { x: number;}, ...objs: { y: number;}[]) => number) | ((...objs: { x: number;}[]) => number), arg4: ((a?: { x: number; } | undefined, b?: { x: number; } | undefined) => number) | ((a?: { y: number; } | undefined) => number), arg5: ((a?: { x: number; } | undefined, ...b: { x: number;}[]) => number) | ((a?: { y: number; } | undefined) => number), arg6: ((a?: { x: number; } | undefined, b?: { x: number; } | undefined) => number) | ((...a: { y: number;}[]) => number)) => void +>test4 : (arg1: ((...objs: { x: number;}[]) => number) | ((...objs: { y: number;}[]) => number), arg2: ((a: { x: number;}, b: object) => number) | ((a: object, b: { x: number;}) => number), arg3: ((a: { x: number;}, ...objs: { y: number;}[]) => number) | ((...objs: { x: number;}[]) => number), arg4: ((a?: { x: number;}, b?: { x: number;}) => number) | ((a?: { y: number;}) => number), arg5: ((a?: { x: number;}, ...b: { x: number;}[]) => number) | ((a?: { y: number;}) => number), arg6: ((a?: { x: number;}, b?: { x: number;}) => number) | ((...a: { y: number;}[]) => number)) => void arg1: ((...objs: {x: number}[]) => number) | ((...objs: {y: number}[]) => number), >arg1 : ((...objs: { x: number;}[]) => number) | ((...objs: { y: number;}[]) => number) @@ -138,7 +138,7 @@ function test4( >x : number arg4: ((a?: {x: number}, b?: {x: number}) => number) | ((a?: {y: number}) => number), ->arg4 : ((a?: { x: number; } | undefined, b?: { x: number; } | undefined) => number) | ((a?: { y: number; } | undefined) => number) +>arg4 : ((a?: { x: number;}, b?: { x: number;}) => number) | ((a?: { y: number;}) => number) >a : { x: number; } | undefined >x : number >b : { x: number; } | undefined @@ -147,7 +147,7 @@ function test4( >y : number arg5: ((a?: {x: number}, ...b: {x: number}[]) => number) | ((a?: {y: number}) => number), ->arg5 : ((a?: { x: number; } | undefined, ...b: { x: number;}[]) => number) | ((a?: { y: number; } | undefined) => number) +>arg5 : ((a?: { x: number;}, ...b: { x: number;}[]) => number) | ((a?: { y: number;}) => number) >a : { x: number; } | undefined >x : number >b : { x: number; }[] @@ -156,7 +156,7 @@ function test4( >y : number arg6: ((a?: {x: number}, b?: {x: number}) => number) | ((...a: {y: number}[]) => number), ->arg6 : ((a?: { x: number; } | undefined, b?: { x: number; } | undefined) => number) | ((...a: { y: number;}[]) => number) +>arg6 : ((a?: { x: number;}, b?: { x: number;}) => number) | ((...a: { y: number;}[]) => number) >a : { x: number; } | undefined >x : number >b : { x: number; } | undefined @@ -339,7 +339,7 @@ function test5() { // Pair of non-like intrinsics function render(url?: string): React.ReactNode { ->render : (url?: string | undefined) => React.ReactNode +>render : (url?: string) => React.ReactNode >url : string | undefined >React : any diff --git a/tests/baselines/reference/circularOptionalityRemoval.types b/tests/baselines/reference/circularOptionalityRemoval.types index 5783b24a6c379..f35bd580699b7 100644 --- a/tests/baselines/reference/circularOptionalityRemoval.types +++ b/tests/baselines/reference/circularOptionalityRemoval.types @@ -12,7 +12,7 @@ function fn1(x: number | undefined = x > 0 ? x : 0) { } // Report from user function fn2(x?: string = someCondition ? 'value1' : x) { } ->fn2 : (x?: string | undefined) => void +>fn2 : (x?: string) => void >x : string | undefined >someCondition ? 'value1' : x : string | undefined >someCondition : any diff --git a/tests/baselines/reference/contextuallyTypedParametersWithInitializers.types b/tests/baselines/reference/contextuallyTypedParametersWithInitializers.types index db65878b320d3..e39e3bde4d733 100644 --- a/tests/baselines/reference/contextuallyTypedParametersWithInitializers.types +++ b/tests/baselines/reference/contextuallyTypedParametersWithInitializers.types @@ -21,7 +21,7 @@ declare function id4 any>(input: T): T; >input : T declare function id5 any>(input: T): T; ->id5 : any>(input: T) => T +>id5 : any>(input: T) => T >x : number | undefined >input : T diff --git a/tests/baselines/reference/controlFlowAliasing.types b/tests/baselines/reference/controlFlowAliasing.types index b7c73a1d9fa62..1f97602b3f290 100644 --- a/tests/baselines/reference/controlFlowAliasing.types +++ b/tests/baselines/reference/controlFlowAliasing.types @@ -532,7 +532,7 @@ function f27(outer: { obj: { kind: 'foo', foo: string } | { kind: 'bar', bar: nu } function f28(obj?: { kind: 'foo', foo: string } | { kind: 'bar', bar: number }) { ->f28 : (obj?: { kind: 'foo'; foo: string; } | { kind: 'bar'; bar: number; } | undefined) => void +>f28 : (obj?: { kind: 'foo'; foo: string;} | { kind: 'bar'; bar: number;}) => void >obj : { kind: 'foo'; foo: string; } | { kind: 'bar'; bar: number; } | undefined >kind : "foo" >foo : string diff --git a/tests/baselines/reference/controlFlowForIndexSignatures.types b/tests/baselines/reference/controlFlowForIndexSignatures.types index 94db82e959c44..20fff99f2c158 100644 --- a/tests/baselines/reference/controlFlowForIndexSignatures.types +++ b/tests/baselines/reference/controlFlowForIndexSignatures.types @@ -10,7 +10,7 @@ const boo: Foo = { bar: 'bar' }; >'bar' : "bar" function a(aboo1?: Foo) { ->a : (aboo1?: Foo | undefined) => void +>a : (aboo1?: Foo) => void >aboo1 : Foo | undefined if (!aboo1) return; diff --git a/tests/baselines/reference/controlFlowOptionalChain.types b/tests/baselines/reference/controlFlowOptionalChain.types index 823d07ca8bf7d..8eb843fb0600b 100644 --- a/tests/baselines/reference/controlFlowOptionalChain.types +++ b/tests/baselines/reference/controlFlowOptionalChain.types @@ -1882,7 +1882,7 @@ type Shape = >radius : number function getArea(shape?: Shape) { ->getArea : (shape?: Shape | undefined) => number +>getArea : (shape?: Shape) => number >shape : Shape | undefined switch (shape?.type) { diff --git a/tests/baselines/reference/defaultParameterAddsUndefinedWithStrictNullChecks.types b/tests/baselines/reference/defaultParameterAddsUndefinedWithStrictNullChecks.types index 2d6e2966a2dd9..06b51c2eeace6 100644 --- a/tests/baselines/reference/defaultParameterAddsUndefinedWithStrictNullChecks.types +++ b/tests/baselines/reference/defaultParameterAddsUndefinedWithStrictNullChecks.types @@ -1,6 +1,6 @@ === tests/cases/compiler/defaultParameterAddsUndefinedWithStrictNullChecks.ts === function f(addUndefined1 = "J", addUndefined2?: number) { ->f : (addUndefined1?: string, addUndefined2?: number | undefined) => number +>f : (addUndefined1?: string, addUndefined2?: number) => number >addUndefined1 : string >"J" : "J" >addUndefined2 : number | undefined diff --git a/tests/baselines/reference/destructureOptionalParameter.types b/tests/baselines/reference/destructureOptionalParameter.types index 984b2da856ae7..01b45c1cb4bf4 100644 --- a/tests/baselines/reference/destructureOptionalParameter.types +++ b/tests/baselines/reference/destructureOptionalParameter.types @@ -1,6 +1,6 @@ === tests/cases/compiler/destructureOptionalParameter.ts === declare function f1({ a, b }?: { a: number, b: string }): void; ->f1 : ({ a, b }?: { a: number; b: string; } | undefined) => void +>f1 : ({ a, b }?: { a: number; b: string;}) => void >a : number >b : string >a : number diff --git a/tests/baselines/reference/destructuringAssignmentWithDefault.types b/tests/baselines/reference/destructuringAssignmentWithDefault.types index 379bfe8b3bdbd..170d1d26ba509 100644 --- a/tests/baselines/reference/destructuringAssignmentWithDefault.types +++ b/tests/baselines/reference/destructuringAssignmentWithDefault.types @@ -61,7 +61,7 @@ function f1(options?: { color?: string, width?: number }) { } function f2(options?: [string?, number?]) { ->f2 : (options?: [(string | undefined)?, (number | undefined)?] | undefined) => void +>f2 : (options?: [string?, number?]) => void >options : [(string | undefined)?, (number | undefined)?] | undefined let [str, num] = options || []; @@ -133,7 +133,7 @@ function f3(options?: { color: string, width: number }) { } function f4(options?: [string, number]) { ->f4 : (options?: [string, number] | undefined) => void +>f4 : (options?: [string, number]) => void >options : [string, number] | undefined let [str, num] = options || []; diff --git a/tests/baselines/reference/genericFunctionInference1.types b/tests/baselines/reference/genericFunctionInference1.types index d76a85dd43d85..9dd28cea1a72e 100644 --- a/tests/baselines/reference/genericFunctionInference1.types +++ b/tests/baselines/reference/genericFunctionInference1.types @@ -801,7 +801,7 @@ const fn20 = pipe((_a?: {}) => 1); >fn20 : (_a?: {} | undefined) => number >pipe((_a?: {}) => 1) : (_a?: {} | undefined) => number >pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } ->(_a?: {}) => 1 : (_a?: {} | undefined) => number +>(_a?: {}) => 1 : (_a?: {}) => number >_a : {} | undefined >1 : 1 @@ -968,7 +968,7 @@ const fn62 = pipe( // Repro from #30297 declare function foo2(fn: T, a?: U, b?: U): [T, U]; ->foo2 : (fn: T, a?: U | undefined, b?: U | undefined) => [T, U] +>foo2 : (fn: T, a?: U, b?: U) => [T, U] >fn : T >a : U | undefined >b : U | undefined diff --git a/tests/baselines/reference/genericRestParameters1.types b/tests/baselines/reference/genericRestParameters1.types index 687ab9751ddec..cbc4e9410755c 100644 --- a/tests/baselines/reference/genericRestParameters1.types +++ b/tests/baselines/reference/genericRestParameters1.types @@ -570,7 +570,7 @@ f23(); >f23 : () => string[] declare const g20: (x: number, y?: string, z?: boolean) => string[]; ->g20 : (x: number, y?: string | undefined, z?: boolean | undefined) => string[] +>g20 : (x: number, y?: string, z?: boolean) => string[] >x : number >y : string | undefined >z : boolean | undefined diff --git a/tests/baselines/reference/indexedAccessNormalization.types b/tests/baselines/reference/indexedAccessNormalization.types index 53d57f4319ae7..418be2989a710 100644 --- a/tests/baselines/reference/indexedAccessNormalization.types +++ b/tests/baselines/reference/indexedAccessNormalization.types @@ -11,7 +11,7 @@ type MyMap = { } declare function g(value?: T): void; ->g : (value?: T | undefined) => void +>g : (value?: T) => void >value : T | undefined function f1(mymap: MyMap, k: keyof M) { diff --git a/tests/baselines/reference/inferFromBindingPattern.types b/tests/baselines/reference/inferFromBindingPattern.types index 802fd56f7fcc3..ee217fafa8617 100644 --- a/tests/baselines/reference/inferFromBindingPattern.types +++ b/tests/baselines/reference/inferFromBindingPattern.types @@ -60,7 +60,7 @@ interface Person { } declare function selectJohn(props?: SelectProps): SelectResult; ->selectJohn : (props?: SelectProps | undefined) => SelectResult +>selectJohn : (props?: SelectProps) => SelectResult >props : SelectProps | undefined const [person] = selectJohn(); @@ -91,7 +91,7 @@ declare function makeTuple(arg: T1): [T1]; >arg : T1 declare function stringy(arg?: T): T; ->stringy : (arg?: T | undefined) => T +>stringy : (arg?: T) => T >arg : T | undefined const isStringTuple = makeTuple(stringy()); // [string] diff --git a/tests/baselines/reference/inferenceErasedSignatures.types b/tests/baselines/reference/inferenceErasedSignatures.types index 84f64ffda5682..382cc08394ff8 100644 --- a/tests/baselines/reference/inferenceErasedSignatures.types +++ b/tests/baselines/reference/inferenceErasedSignatures.types @@ -15,7 +15,7 @@ abstract class SomeAbstractClass extends SomeBaseClass { >SomeBaseClass : SomeBaseClass foo!: (r?: R) => void; ->foo : (r?: R | undefined) => void +>foo : (r?: R) => void >r : R | undefined bar!: (r?: any) => void; @@ -72,7 +72,7 @@ interface BaseType { >c : T1 useT2(r?: T2): void; ->useT2 : (r?: T2 | undefined) => void +>useT2 : (r?: T2) => void >r : T2 | undefined unrelatedButSomehowRelevant(r?: any): void; @@ -99,7 +99,7 @@ interface StructuralVersion { >c : number useT2(r?: boolean): void; ->useT2 : (r?: boolean | undefined) => void +>useT2 : (r?: boolean) => void >r : boolean | undefined unrelatedButSomehowRelevant(r?: any): void; diff --git a/tests/baselines/reference/initializedParameterBeforeNonoptionalNotOptional.types b/tests/baselines/reference/initializedParameterBeforeNonoptionalNotOptional.types index 5035da7bcef17..2656522f57e08 100644 --- a/tests/baselines/reference/initializedParameterBeforeNonoptionalNotOptional.types +++ b/tests/baselines/reference/initializedParameterBeforeNonoptionalNotOptional.types @@ -1,6 +1,6 @@ === tests/cases/compiler/index.d.ts === export declare function foo({a}?: { ->foo : ({ a }?: { a?: string | undefined; } | undefined) => void +>foo : ({ a }?: { a?: string;}) => void >a : string | undefined a?: string; diff --git a/tests/baselines/reference/intersectionWithConflictingPrivates.types b/tests/baselines/reference/intersectionWithConflictingPrivates.types index 62861bb4ec597..d7f8e4a9dedaa 100644 --- a/tests/baselines/reference/intersectionWithConflictingPrivates.types +++ b/tests/baselines/reference/intersectionWithConflictingPrivates.types @@ -138,7 +138,7 @@ class Foo { } private async bar(node: CommitFileNode | ResultsFileNode | StashFileNode | StatusFileNode, options?: {}) { ->bar : (node: CommitFileNode | ResultsFileNode | StashFileNode | StatusFileNode, options?: {} | undefined) => Promise +>bar : (node: CommitFileNode | ResultsFileNode | StashFileNode | StatusFileNode, options?: {}) => Promise >node : CommitFileNode | ResultsFileNode | StashFileNode | StatusFileNode >options : {} | undefined diff --git a/tests/baselines/reference/jsDeclarationsReactComponents.js b/tests/baselines/reference/jsDeclarationsReactComponents.js index 9c0373e83e739..fb0972b36ed3a 100644 --- a/tests/baselines/reference/jsDeclarationsReactComponents.js +++ b/tests/baselines/reference/jsDeclarationsReactComponents.js @@ -216,7 +216,7 @@ declare const TabbedShowLayout: { }; } & ((props?: { elem: string; -} | undefined) => JSX.Element); +}) => JSX.Element); //// [jsDeclarationsReactComponents4.d.ts] export default TabbedShowLayout; declare function TabbedShowLayout(prop: { diff --git a/tests/baselines/reference/jsxNamespaceGlobalReexport.types b/tests/baselines/reference/jsxNamespaceGlobalReexport.types index 12226ae9e13a1..655a3a7cab9d9 100644 --- a/tests/baselines/reference/jsxNamespaceGlobalReexport.types +++ b/tests/baselines/reference/jsxNamespaceGlobalReexport.types @@ -90,7 +90,7 @@ import { JSXInternal } from '..'; >JSXInternal : any export function jsx( ->jsx : { (type: string, props: JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes & Record & { children?: ComponentChild;}, key?: string | undefined): VNode;

(type: ComponentType

, props: P & { children?: ComponentChild | undefined; }, key?: string | undefined): VNode; } +>jsx : { (type: string, props: JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes & Record & { children?: ComponentChild;}, key?: string): VNode;

(type: ComponentType

, props: P & { children?: ComponentChild | undefined; }, key?: string | undefined): VNode; } type: string, >type : string @@ -110,7 +110,7 @@ export function jsx( ): VNode; export function jsx

( ->jsx : { (type: string, props: JSXInternal.HTMLAttributes<{}> & JSXInternal.SVGAttributes<{}> & Record & { children?: ComponentChild | undefined; }, key?: string | undefined): VNode;

(type: ComponentType

, props: Attributes & P & { children?: ComponentChild;}, key?: string | undefined): VNode; } +>jsx : { (type: string, props: JSXInternal.HTMLAttributes<{}> & JSXInternal.SVGAttributes<{}> & Record & { children?: ComponentChild | undefined; }, key?: string | undefined): VNode;

(type: ComponentType

, props: Attributes & P & { children?: ComponentChild;}, key?: string): VNode; } type: ComponentType

, >type : ComponentType

@@ -125,7 +125,7 @@ export function jsx

( ): VNode; export function jsxs( ->jsxs : { (type: string, props: JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes & Record & { children?: ComponentChild[];}, key?: string | undefined): VNode;

(type: ComponentType

, props: P & { children?: ComponentChild[] | undefined; }, key?: string | undefined): VNode; } +>jsxs : { (type: string, props: JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes & Record & { children?: ComponentChild[];}, key?: string): VNode;

(type: ComponentType

, props: P & { children?: ComponentChild[] | undefined; }, key?: string | undefined): VNode; } type: string, >type : string @@ -145,7 +145,7 @@ export function jsxs( ): VNode; export function jsxs

( ->jsxs : { (type: string, props: JSXInternal.HTMLAttributes<{}> & JSXInternal.SVGAttributes<{}> & Record & { children?: ComponentChild[] | undefined; }, key?: string | undefined): VNode;

(type: ComponentType

, props: Attributes & P & { children?: ComponentChild[];}, key?: string | undefined): VNode; } +>jsxs : { (type: string, props: JSXInternal.HTMLAttributes<{}> & JSXInternal.SVGAttributes<{}> & Record & { children?: ComponentChild[] | undefined; }, key?: string | undefined): VNode;

(type: ComponentType

, props: Attributes & P & { children?: ComponentChild[];}, key?: string): VNode; } type: ComponentType

, >type : ComponentType

@@ -160,7 +160,7 @@ export function jsxs

( ): VNode; export function jsxDEV( ->jsxDEV : { (type: string, props: JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes & Record & { children?: ComponentChildren;}, key?: string | undefined): VNode;

(type: ComponentType

, props: P & { children?: ComponentChildren | undefined; }, key?: string | undefined): VNode; } +>jsxDEV : { (type: string, props: JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes & Record & { children?: ComponentChildren;}, key?: string): VNode;

(type: ComponentType

, props: P & { children?: ComponentChildren | undefined; }, key?: string | undefined): VNode; } type: string, >type : string @@ -180,7 +180,7 @@ export function jsxDEV( ): VNode; export function jsxDEV

( ->jsxDEV : { (type: string, props: JSXInternal.HTMLAttributes<{}> & JSXInternal.SVGAttributes<{}> & Record & { children?: ComponentChildren | undefined; }, key?: string | undefined): VNode;

(type: ComponentType

, props: Attributes & P & { children?: ComponentChildren;}, key?: string | undefined): VNode; } +>jsxDEV : { (type: string, props: JSXInternal.HTMLAttributes<{}> & JSXInternal.SVGAttributes<{}> & Record & { children?: ComponentChildren | undefined; }, key?: string | undefined): VNode;

(type: ComponentType

, props: Attributes & P & { children?: ComponentChildren;}, key?: string): VNode; } type: ComponentType

, >type : ComponentType

diff --git a/tests/baselines/reference/jsxNamespaceGlobalReexportMissingAliasTarget.types b/tests/baselines/reference/jsxNamespaceGlobalReexportMissingAliasTarget.types index 2e27ccbfa7433..99dcad4b53f95 100644 --- a/tests/baselines/reference/jsxNamespaceGlobalReexportMissingAliasTarget.types +++ b/tests/baselines/reference/jsxNamespaceGlobalReexportMissingAliasTarget.types @@ -90,7 +90,7 @@ import { JSXInternal } from '..'; >JSXInternal : any export function jsx( ->jsx : { (type: string, props: JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes & Record & { children?: ComponentChild;}, key?: string | undefined): VNode;

(type: ComponentType

, props: P & { children?: ComponentChild | undefined; }, key?: string | undefined): VNode; } +>jsx : { (type: string, props: JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes & Record & { children?: ComponentChild;}, key?: string): VNode;

(type: ComponentType

, props: P & { children?: ComponentChild | undefined; }, key?: string | undefined): VNode; } type: string, >type : string @@ -110,7 +110,7 @@ export function jsx( ): VNode; export function jsx

( ->jsx : { (type: string, props: JSXInternal.HTMLAttributes<{}> & JSXInternal.SVGAttributes<{}> & Record & { children?: ComponentChild | undefined; }, key?: string | undefined): VNode;

(type: ComponentType

, props: Attributes & P & { children?: ComponentChild;}, key?: string | undefined): VNode; } +>jsx : { (type: string, props: JSXInternal.HTMLAttributes<{}> & JSXInternal.SVGAttributes<{}> & Record & { children?: ComponentChild | undefined; }, key?: string | undefined): VNode;

(type: ComponentType

, props: Attributes & P & { children?: ComponentChild;}, key?: string): VNode; } type: ComponentType

, >type : ComponentType

@@ -125,7 +125,7 @@ export function jsx

( ): VNode; export function jsxs( ->jsxs : { (type: string, props: JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes & Record & { children?: ComponentChild[];}, key?: string | undefined): VNode;

(type: ComponentType

, props: P & { children?: ComponentChild[] | undefined; }, key?: string | undefined): VNode; } +>jsxs : { (type: string, props: JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes & Record & { children?: ComponentChild[];}, key?: string): VNode;

(type: ComponentType

, props: P & { children?: ComponentChild[] | undefined; }, key?: string | undefined): VNode; } type: string, >type : string @@ -145,7 +145,7 @@ export function jsxs( ): VNode; export function jsxs

( ->jsxs : { (type: string, props: JSXInternal.HTMLAttributes<{}> & JSXInternal.SVGAttributes<{}> & Record & { children?: ComponentChild[] | undefined; }, key?: string | undefined): VNode;

(type: ComponentType

, props: Attributes & P & { children?: ComponentChild[];}, key?: string | undefined): VNode; } +>jsxs : { (type: string, props: JSXInternal.HTMLAttributes<{}> & JSXInternal.SVGAttributes<{}> & Record & { children?: ComponentChild[] | undefined; }, key?: string | undefined): VNode;

(type: ComponentType

, props: Attributes & P & { children?: ComponentChild[];}, key?: string): VNode; } type: ComponentType

, >type : ComponentType

@@ -160,7 +160,7 @@ export function jsxs

( ): VNode; export function jsxDEV( ->jsxDEV : { (type: string, props: JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes & Record & { children?: ComponentChildren;}, key?: string | undefined): VNode;

(type: ComponentType

, props: P & { children?: ComponentChildren | undefined; }, key?: string | undefined): VNode; } +>jsxDEV : { (type: string, props: JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes & Record & { children?: ComponentChildren;}, key?: string): VNode;

(type: ComponentType

, props: P & { children?: ComponentChildren | undefined; }, key?: string | undefined): VNode; } type: string, >type : string @@ -180,7 +180,7 @@ export function jsxDEV( ): VNode; export function jsxDEV

( ->jsxDEV : { (type: string, props: JSXInternal.HTMLAttributes<{}> & JSXInternal.SVGAttributes<{}> & Record & { children?: ComponentChildren | undefined; }, key?: string | undefined): VNode;

(type: ComponentType

, props: Attributes & P & { children?: ComponentChildren;}, key?: string | undefined): VNode; } +>jsxDEV : { (type: string, props: JSXInternal.HTMLAttributes<{}> & JSXInternal.SVGAttributes<{}> & Record & { children?: ComponentChildren | undefined; }, key?: string | undefined): VNode;

(type: ComponentType

, props: Attributes & P & { children?: ComponentChildren;}, key?: string): VNode; } type: ComponentType

, >type : ComponentType

diff --git a/tests/baselines/reference/jsxNamespaceImplicitImportJSXNamespace.types b/tests/baselines/reference/jsxNamespaceImplicitImportJSXNamespace.types index a8d93e63512eb..71651f958b0a3 100644 --- a/tests/baselines/reference/jsxNamespaceImplicitImportJSXNamespace.types +++ b/tests/baselines/reference/jsxNamespaceImplicitImportJSXNamespace.types @@ -90,7 +90,7 @@ import { JSXInternal } from '..'; >JSXInternal : any export function jsx( ->jsx : { (type: string, props: JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes & Record & { children?: ComponentChild;}, key?: string | undefined): VNode;

(type: ComponentType

, props: P & { children?: ComponentChild | undefined; }, key?: string | undefined): VNode; } +>jsx : { (type: string, props: JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes & Record & { children?: ComponentChild;}, key?: string): VNode;

(type: ComponentType

, props: P & { children?: ComponentChild | undefined; }, key?: string | undefined): VNode; } type: string, >type : string @@ -110,7 +110,7 @@ export function jsx( ): VNode; export function jsx

( ->jsx : { (type: string, props: JSXInternal.HTMLAttributes<{}> & JSXInternal.SVGAttributes<{}> & Record & { children?: ComponentChild | undefined; }, key?: string | undefined): VNode;

(type: ComponentType

, props: Attributes & P & { children?: ComponentChild;}, key?: string | undefined): VNode; } +>jsx : { (type: string, props: JSXInternal.HTMLAttributes<{}> & JSXInternal.SVGAttributes<{}> & Record & { children?: ComponentChild | undefined; }, key?: string | undefined): VNode;

(type: ComponentType

, props: Attributes & P & { children?: ComponentChild;}, key?: string): VNode; } type: ComponentType

, >type : ComponentType

@@ -126,7 +126,7 @@ export function jsx

( export function jsxs( ->jsxs : { (type: string, props: JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes & Record & { children?: ComponentChild[];}, key?: string | undefined): VNode;

(type: ComponentType

, props: P & { children?: ComponentChild[] | undefined; }, key?: string | undefined): VNode; } +>jsxs : { (type: string, props: JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes & Record & { children?: ComponentChild[];}, key?: string): VNode;

(type: ComponentType

, props: P & { children?: ComponentChild[] | undefined; }, key?: string | undefined): VNode; } type: string, >type : string @@ -146,7 +146,7 @@ export function jsxs( ): VNode; export function jsxs

( ->jsxs : { (type: string, props: JSXInternal.HTMLAttributes<{}> & JSXInternal.SVGAttributes<{}> & Record & { children?: ComponentChild[] | undefined; }, key?: string | undefined): VNode;

(type: ComponentType

, props: Attributes & P & { children?: ComponentChild[];}, key?: string | undefined): VNode; } +>jsxs : { (type: string, props: JSXInternal.HTMLAttributes<{}> & JSXInternal.SVGAttributes<{}> & Record & { children?: ComponentChild[] | undefined; }, key?: string | undefined): VNode;

(type: ComponentType

, props: Attributes & P & { children?: ComponentChild[];}, key?: string): VNode; } type: ComponentType

, >type : ComponentType

@@ -162,7 +162,7 @@ export function jsxs

( export function jsxDEV( ->jsxDEV : { (type: string, props: JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes & Record & { children?: ComponentChildren;}, key?: string | undefined): VNode;

(type: ComponentType

, props: P & { children?: ComponentChildren | undefined; }, key?: string | undefined): VNode; } +>jsxDEV : { (type: string, props: JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes & Record & { children?: ComponentChildren;}, key?: string): VNode;

(type: ComponentType

, props: P & { children?: ComponentChildren | undefined; }, key?: string | undefined): VNode; } type: string, >type : string @@ -182,7 +182,7 @@ export function jsxDEV( ): VNode; export function jsxDEV

( ->jsxDEV : { (type: string, props: JSXInternal.HTMLAttributes<{}> & JSXInternal.SVGAttributes<{}> & Record & { children?: ComponentChildren | undefined; }, key?: string | undefined): VNode;

(type: ComponentType

, props: Attributes & P & { children?: ComponentChildren;}, key?: string | undefined): VNode; } +>jsxDEV : { (type: string, props: JSXInternal.HTMLAttributes<{}> & JSXInternal.SVGAttributes<{}> & Record & { children?: ComponentChildren | undefined; }, key?: string | undefined): VNode;

(type: ComponentType

, props: Attributes & P & { children?: ComponentChildren;}, key?: string): VNode; } type: ComponentType

, >type : ComponentType

diff --git a/tests/baselines/reference/leaveOptionalParameterAsWritten.js b/tests/baselines/reference/leaveOptionalParameterAsWritten.js new file mode 100644 index 0000000000000..d2a519390a716 --- /dev/null +++ b/tests/baselines/reference/leaveOptionalParameterAsWritten.js @@ -0,0 +1,37 @@ +//// [tests/cases/conformance/declarationEmit/leaveOptionalParameterAsWritten.ts] //// + +//// [a.ts] +export interface Foo {} + +//// [b.ts] +import * as a from "./a"; +declare global { + namespace teams { + export namespace calling { + export import Foo = a.Foo; + } + } +} + +//// [c.ts] +type Foo = teams.calling.Foo; +export const bar = (p?: Foo) => {} + + + +//// [a.d.ts] +export interface Foo { +} +//// [b.d.ts] +import * as a from "./a"; +declare global { + namespace teams { + namespace calling { + export import Foo = a.Foo; + } + } +} +//// [c.d.ts] +declare type Foo = teams.calling.Foo; +export declare const bar: (p?: Foo) => void; +export {}; diff --git a/tests/baselines/reference/leaveOptionalParameterAsWritten.symbols b/tests/baselines/reference/leaveOptionalParameterAsWritten.symbols new file mode 100644 index 0000000000000..fbf7d565c51d7 --- /dev/null +++ b/tests/baselines/reference/leaveOptionalParameterAsWritten.symbols @@ -0,0 +1,37 @@ +=== tests/cases/conformance/declarationEmit/a.ts === +export interface Foo {} +>Foo : Symbol(Foo, Decl(a.ts, 0, 0)) + +=== tests/cases/conformance/declarationEmit/b.ts === +import * as a from "./a"; +>a : Symbol(a, Decl(b.ts, 0, 6)) + +declare global { +>global : Symbol(global, Decl(b.ts, 0, 25)) + + namespace teams { +>teams : Symbol(teams, Decl(b.ts, 1, 16)) + + export namespace calling { +>calling : Symbol(calling, Decl(b.ts, 2, 19)) + + export import Foo = a.Foo; +>Foo : Symbol(Foo, Decl(b.ts, 3, 30)) +>a : Symbol(a, Decl(b.ts, 0, 6)) +>Foo : Symbol(Foo, Decl(a.ts, 0, 0)) + } + } +} + +=== tests/cases/conformance/declarationEmit/c.ts === +type Foo = teams.calling.Foo; +>Foo : Symbol(Foo, Decl(c.ts, 0, 0)) +>teams : Symbol(teams, Decl(b.ts, 1, 16)) +>calling : Symbol(teams.calling, Decl(b.ts, 2, 19)) +>Foo : Symbol(teams.calling.Foo, Decl(b.ts, 3, 30)) + +export const bar = (p?: Foo) => {} +>bar : Symbol(bar, Decl(c.ts, 1, 12)) +>p : Symbol(p, Decl(c.ts, 1, 20)) +>Foo : Symbol(Foo, Decl(c.ts, 0, 0)) + diff --git a/tests/baselines/reference/leaveOptionalParameterAsWritten.types b/tests/baselines/reference/leaveOptionalParameterAsWritten.types new file mode 100644 index 0000000000000..14632b2b28df4 --- /dev/null +++ b/tests/baselines/reference/leaveOptionalParameterAsWritten.types @@ -0,0 +1,35 @@ +=== tests/cases/conformance/declarationEmit/a.ts === +export interface Foo {} +No type information for this code. +No type information for this code.=== tests/cases/conformance/declarationEmit/b.ts === +import * as a from "./a"; +>a : typeof a + +declare global { +>global : typeof global + + namespace teams { +>teams : typeof teams + + export namespace calling { +>calling : typeof calling + + export import Foo = a.Foo; +>Foo : any +>a : typeof a +>Foo : Foo + } + } +} + +=== tests/cases/conformance/declarationEmit/c.ts === +type Foo = teams.calling.Foo; +>Foo : import("tests/cases/conformance/declarationEmit/a").Foo +>teams : any +>calling : any + +export const bar = (p?: Foo) => {} +>bar : (p?: Foo) => void +>(p?: Foo) => {} : (p?: Foo) => void +>p : import("tests/cases/conformance/declarationEmit/a").Foo | undefined + diff --git a/tests/baselines/reference/neverReturningFunctions1.types b/tests/baselines/reference/neverReturningFunctions1.types index c832fa660dd88..49ec260ad2053 100644 --- a/tests/baselines/reference/neverReturningFunctions1.types +++ b/tests/baselines/reference/neverReturningFunctions1.types @@ -1,6 +1,6 @@ === tests/cases/conformance/controlFlow/neverReturningFunctions1.ts === function fail(message?: string): never { ->fail : (message?: string | undefined) => never +>fail : (message?: string) => never >message : string | undefined throw new Error(message); @@ -62,9 +62,9 @@ function f03(x: string) { } function f11(x: string | undefined, fail: (message?: string) => never) { ->f11 : (x: string | undefined, fail: (message?: string | undefined) => never) => void +>f11 : (x: string | undefined, fail: (message?: string) => never) => void >x : string | undefined ->fail : (message?: string | undefined) => never +>fail : (message?: string) => never >message : string | undefined if (x === undefined) fail("undefined argument"); @@ -82,9 +82,9 @@ function f11(x: string | undefined, fail: (message?: string) => never) { } function f12(x: number, fail: (message?: string) => never): number { ->f12 : (x: number, fail: (message?: string | undefined) => never) => number +>f12 : (x: number, fail: (message?: string) => never) => number >x : number ->fail : (message?: string | undefined) => never +>fail : (message?: string) => never >message : string | undefined if (x >= 0) return x; @@ -103,9 +103,9 @@ function f12(x: number, fail: (message?: string) => never): number { } function f13(x: string, fail: (message?: string) => never) { ->f13 : (x: string, fail: (message?: string | undefined) => never) => void +>f13 : (x: string, fail: (message?: string) => never) => void >x : string ->fail : (message?: string | undefined) => never +>fail : (message?: string) => never >message : string | undefined x; // string @@ -123,7 +123,7 @@ namespace Debug { >Debug : typeof Debug export declare function fail(message?: string): never; ->fail : (message?: string | undefined) => never +>fail : (message?: string) => never >message : string | undefined } @@ -208,7 +208,7 @@ class Test { >Test : Test fail(message?: string): never { ->fail : (message?: string | undefined) => never +>fail : (message?: string) => never >message : string | undefined throw new Error(message); @@ -496,7 +496,7 @@ export interface Component { >system : any init(data?: T): void; ->init : (data?: T | undefined) => void +>init : (data?: T) => void >data : T | undefined pause(): void; diff --git a/tests/baselines/reference/noCrashOnThisTypeUsage.types b/tests/baselines/reference/noCrashOnThisTypeUsage.types index d0d3048cabf3b..6be36b9174ddd 100644 --- a/tests/baselines/reference/noCrashOnThisTypeUsage.types +++ b/tests/baselines/reference/noCrashOnThisTypeUsage.types @@ -5,7 +5,7 @@ interface IListenable { >null : null observe(handler: (change: any, oldValue?: any) => void, fireImmediately?: boolean): void ->observe : (handler: (change: any, oldValue?: any) => void, fireImmediately?: boolean | undefined) => void +>observe : (handler: (change: any, oldValue?: any) => void, fireImmediately?: boolean) => void >handler : (change: any, oldValue?: any) => void >change : any >oldValue : any @@ -62,7 +62,7 @@ export class ObservableValue { >[] : never[] observe(handler: (change: any, oldValue?: any) => void, fireImmediately?: boolean) {} ->observe : (handler: (change: any, oldValue?: any) => void, fireImmediately?: boolean | undefined) => void +>observe : (handler: (change: any, oldValue?: any) => void, fireImmediately?: boolean) => void >handler : (change: any, oldValue?: any) => void >change : any >oldValue : any diff --git a/tests/baselines/reference/observableInferenceCanBeMade.types b/tests/baselines/reference/observableInferenceCanBeMade.types index 6931e042adb5b..6bc2aaf43749f 100644 --- a/tests/baselines/reference/observableInferenceCanBeMade.types +++ b/tests/baselines/reference/observableInferenceCanBeMade.types @@ -14,7 +14,7 @@ type ObservedValueOf = O extends ObservableInput ? T : never; interface Subscribable { subscribe(next?: (value: T) => void, error?: (error: any) => void, complete?: () => void): void; ->subscribe : (next?: ((value: T) => void) | undefined, error?: ((error: any) => void) | undefined, complete?: (() => void) | undefined) => void +>subscribe : (next?: ((value: T) => void) | undefined, error?: ((error: any) => void) | undefined, complete?: () => void) => void >next : ((value: T) => void) | undefined >value : T >error : ((error: any) => void) | undefined @@ -29,7 +29,7 @@ declare class Observable implements Subscribable { >Observable : Observable subscribe(next?: (value: T) => void, error?: (error: any) => void, complete?: () => void): void; ->subscribe : (next?: ((value: T) => void) | undefined, error?: ((error: any) => void) | undefined, complete?: (() => void) | undefined) => void +>subscribe : (next?: ((value: T) => void) | undefined, error?: ((error: any) => void) | undefined, complete?: () => void) => void >next : ((value: T) => void) | undefined >value : T >error : ((error: any) => void) | undefined diff --git a/tests/baselines/reference/optionalParameterRetainsNull.types b/tests/baselines/reference/optionalParameterRetainsNull.types index 94bf71a6f3d42..f1b8f58184195 100644 --- a/tests/baselines/reference/optionalParameterRetainsNull.types +++ b/tests/baselines/reference/optionalParameterRetainsNull.types @@ -9,7 +9,7 @@ let a = { >{ test (a: K, b?: Bar[K] | null) { }} : { test(a: K, b?: Bar[K] | null | undefined): void; } test (a: K, b?: Bar[K] | null) { } ->test : (a: K, b?: Bar[K] | null | undefined) => void +>test : (a: K, b?: Bar[K] | null) => void >a : K >b : Bar[K] | null | undefined >null : null diff --git a/tests/baselines/reference/primitiveUnionDetection.types b/tests/baselines/reference/primitiveUnionDetection.types index 03e1ed19884f4..8c9508247c3e9 100644 --- a/tests/baselines/reference/primitiveUnionDetection.types +++ b/tests/baselines/reference/primitiveUnionDetection.types @@ -5,7 +5,7 @@ type Kind = "one" | "two" | "three"; >Kind : "one" | "two" | "three" declare function getInterfaceFromString(options?: { type?: T } & { type?: Kind }): T; ->getInterfaceFromString : (options?: ({ type?: T | undefined; } & { type?: Kind | undefined; }) | undefined) => T +>getInterfaceFromString : (options?: { type?: T;} & { type?: Kind;}) => T >options : ({ type?: T | undefined; } & { type?: Kind | undefined; }) | undefined >type : T | undefined >type : Kind | undefined diff --git a/tests/baselines/reference/propertyAccessWidening.types b/tests/baselines/reference/propertyAccessWidening.types index 244b43be69fce..7185b28f4ca8d 100644 --- a/tests/baselines/reference/propertyAccessWidening.types +++ b/tests/baselines/reference/propertyAccessWidening.types @@ -54,7 +54,7 @@ function g2(headerNames: any) { // Object in property or element access is widened when target of assignment function foo(options?: { a: string, b: number }) { ->foo : (options?: { a: string; b: number; } | undefined) => void +>foo : (options?: { a: string; b: number;}) => void >options : { a: string; b: number; } | undefined >a : string >b : number diff --git a/tests/baselines/reference/spreadIdenticalTypesRemoved.types b/tests/baselines/reference/spreadIdenticalTypesRemoved.types index 6695770ccc3ed..693b73ef23c4d 100644 --- a/tests/baselines/reference/spreadIdenticalTypesRemoved.types +++ b/tests/baselines/reference/spreadIdenticalTypesRemoved.types @@ -17,7 +17,7 @@ interface Animal { } function clonePet(pet: Animal, fullCopy?: boolean) { ->clonePet : (pet: Animal, fullCopy?: boolean | undefined) => { name: string; kind: string; age?: number | undefined; location?: string | undefined; owner?: object | undefined; } +>clonePet : (pet: Animal, fullCopy?: boolean) => { name: string; kind: string; age?: number | undefined; location?: string | undefined; owner?: object | undefined; } >pet : Animal >fullCopy : boolean | undefined diff --git a/tests/baselines/reference/spreadUnion3.types b/tests/baselines/reference/spreadUnion3.types index 62a2fa2da733c..8c4b955ff1a38 100644 --- a/tests/baselines/reference/spreadUnion3.types +++ b/tests/baselines/reference/spreadUnion3.types @@ -18,7 +18,7 @@ f(undefined) function g(t?: { a: number } | null): void { ->g : (t?: { a: number; } | null | undefined) => void +>g : (t?: { a: number;} | null) => void >t : { a: number; } | null | undefined >a : number >null : null diff --git a/tests/baselines/reference/stackDepthLimitCastingType.types b/tests/baselines/reference/stackDepthLimitCastingType.types index 27d09998e3010..76d08fdd570bd 100644 --- a/tests/baselines/reference/stackDepthLimitCastingType.types +++ b/tests/baselines/reference/stackDepthLimitCastingType.types @@ -7,7 +7,7 @@ declare global { >Model : Model initialize(attributes?: T, options?: CombinedModelConstructorOptions): void; ->initialize : (attributes?: T | undefined, options?: CombinedModelConstructorOptions | undefined) => void +>initialize : (attributes?: T, options?: CombinedModelConstructorOptions) => void >attributes : T | undefined >options : CombinedModelConstructorOptions | undefined diff --git a/tests/baselines/reference/strictNullLogicalAndOr.types b/tests/baselines/reference/strictNullLogicalAndOr.types index 33881b5d9d72c..6c6cba3356165 100644 --- a/tests/baselines/reference/strictNullLogicalAndOr.types +++ b/tests/baselines/reference/strictNullLogicalAndOr.types @@ -30,7 +30,7 @@ choice(Math.PI); >PI : number function sq(n?: number): number { ->sq : (n?: number | undefined) => number +>sq : (n?: number) => number >n : number | undefined const r = n !== undefined && n*n || 0; diff --git a/tests/baselines/reference/substitutionTypesInIndexedAccessTypes.types b/tests/baselines/reference/substitutionTypesInIndexedAccessTypes.types index a0df1acaa22df..638d2de084c6f 100644 --- a/tests/baselines/reference/substitutionTypesInIndexedAccessTypes.types +++ b/tests/baselines/reference/substitutionTypesInIndexedAccessTypes.types @@ -13,11 +13,11 @@ type Subset = { [key in keyof T]: key extends keyof U ? T[key] : never }; >Subset : Subset declare function withBoundary(args?: Subset): T; ->withBoundary : (args?: Subset | undefined) => T +>withBoundary : (args?: Subset) => T >args : Subset | undefined declare function withoutBoundary(args?: T): T; ->withoutBoundary : (args?: T | undefined) => T +>withoutBoundary : (args?: T) => T >args : T | undefined const boundaryResult = withBoundary({ diff --git a/tests/baselines/reference/thisTypeInObjectLiterals2.types b/tests/baselines/reference/thisTypeInObjectLiterals2.types index 3777ded41acaf..bd96bd68bbd1d 100644 --- a/tests/baselines/reference/thisTypeInObjectLiterals2.types +++ b/tests/baselines/reference/thisTypeInObjectLiterals2.types @@ -72,7 +72,7 @@ let obj1 = { // contextual type. type Point = { ->Point : { x: number; y: number; z?: number | undefined; moveBy(dx: number, dy: number, dz?: number | undefined): void; } +>Point : { x: number; y: number; z?: number | undefined; moveBy(dx: number, dy: number, dz?: number): void; } x: number; >x : number @@ -84,7 +84,7 @@ type Point = { >z : number | undefined moveBy(dx: number, dy: number, dz?: number): void; ->moveBy : (dx: number, dy: number, dz?: number | undefined) => void +>moveBy : (dx: number, dy: number, dz?: number) => void >dx : number >dy : number >dz : number | undefined diff --git a/tests/baselines/reference/truthinessCallExpressionCoercion.types b/tests/baselines/reference/truthinessCallExpressionCoercion.types index 21c2328455c74..16c86086c20e8 100644 --- a/tests/baselines/reference/truthinessCallExpressionCoercion.types +++ b/tests/baselines/reference/truthinessCallExpressionCoercion.types @@ -1,6 +1,6 @@ === tests/cases/compiler/truthinessCallExpressionCoercion.ts === function onlyErrorsWhenTestingNonNullableFunctionType(required: () => boolean, optional?: () => boolean) { ->onlyErrorsWhenTestingNonNullableFunctionType : (required: () => boolean, optional?: (() => boolean) | undefined) => void +>onlyErrorsWhenTestingNonNullableFunctionType : (required: () => boolean, optional?: () => boolean) => void >required : () => boolean >optional : (() => boolean) | undefined diff --git a/tests/baselines/reference/truthinessCallExpressionCoercion1.types b/tests/baselines/reference/truthinessCallExpressionCoercion1.types index cd9f357a5ed4c..7a0aced375dc9 100644 --- a/tests/baselines/reference/truthinessCallExpressionCoercion1.types +++ b/tests/baselines/reference/truthinessCallExpressionCoercion1.types @@ -1,6 +1,6 @@ === tests/cases/compiler/truthinessCallExpressionCoercion1.ts === function onlyErrorsWhenTestingNonNullableFunctionType(required: () => boolean, optional?: () => boolean) { ->onlyErrorsWhenTestingNonNullableFunctionType : (required: () => boolean, optional?: (() => boolean) | undefined) => void +>onlyErrorsWhenTestingNonNullableFunctionType : (required: () => boolean, optional?: () => boolean) => void >required : () => boolean >optional : (() => boolean) | undefined diff --git a/tests/baselines/reference/truthinessCallExpressionCoercion2.types b/tests/baselines/reference/truthinessCallExpressionCoercion2.types index 85eeacc46f731..96f115a621d09 100644 --- a/tests/baselines/reference/truthinessCallExpressionCoercion2.types +++ b/tests/baselines/reference/truthinessCallExpressionCoercion2.types @@ -14,7 +14,7 @@ declare class B { } function test(required1: () => boolean, required2: () => boolean, b: boolean, optional?: () => boolean) { ->test : (required1: () => boolean, required2: () => boolean, b: boolean, optional?: (() => boolean) | undefined) => void +>test : (required1: () => boolean, required2: () => boolean, b: boolean, optional?: () => boolean) => void >required1 : () => boolean >required2 : () => boolean >b : boolean diff --git a/tests/baselines/reference/unionReductionMutualSubtypes.types b/tests/baselines/reference/unionReductionMutualSubtypes.types index 748826d08f6c9..0cd09be38a6db 100644 --- a/tests/baselines/reference/unionReductionMutualSubtypes.types +++ b/tests/baselines/reference/unionReductionMutualSubtypes.types @@ -15,9 +15,9 @@ declare const val: ReturnVal; >val : ReturnVal function run(options: { something?(b?: string): void }) { ->run : (options: { something?(b?: string | undefined): void; }) => void ->options : { something?(b?: string | undefined): void; } ->something : ((b?: string | undefined) => void) | undefined +>run : (options: { something?(b?: string): void; }) => void +>options : { something?(b?: string): void; } +>something : ((b?: string) => void) | undefined >b : string | undefined const something = options.something ?? val.something; diff --git a/tests/baselines/reference/unionTypeReduction2.types b/tests/baselines/reference/unionTypeReduction2.types index f4f724e6dcdb0..7c79aab4ddfb9 100644 --- a/tests/baselines/reference/unionTypeReduction2.types +++ b/tests/baselines/reference/unionTypeReduction2.types @@ -1,10 +1,10 @@ === tests/cases/conformance/types/union/unionTypeReduction2.ts === function f1(x: { f(): void }, y: { f(x?: string): void }) { ->f1 : (x: { f(): void;}, y: { f(x?: string | undefined): void; }) => void +>f1 : (x: { f(): void;}, y: { f(x?: string): void; }) => void >x : { f(): void; } >f : () => void ->y : { f(x?: string | undefined): void; } ->f : (x?: string | undefined) => void +>y : { f(x?: string): void; } +>f : (x?: string) => void >x : string | undefined let z = !!true ? x : y; // { f(x?: string): void } @@ -31,12 +31,12 @@ function f1(x: { f(): void }, y: { f(x?: string): void }) { } function f2(x: { f(x: string | undefined): void }, y: { f(x?: string): void }) { ->f2 : (x: { f(x: string | undefined): void; }, y: { f(x?: string | undefined): void; }) => void +>f2 : (x: { f(x: string | undefined): void; }, y: { f(x?: string): void; }) => void >x : { f(x: string | undefined): void; } >f : (x: string | undefined) => void >x : string | undefined ->y : { f(x?: string | undefined): void; } ->f : (x?: string | undefined) => void +>y : { f(x?: string): void; } +>f : (x?: string) => void >x : string | undefined let z = !!true ? x : y; // { f(x?: string): void } @@ -63,9 +63,9 @@ function f2(x: { f(x: string | undefined): void }, y: { f(x?: string): void }) { } function f3(x: () => void, y: (x?: string) => void) { ->f3 : (x: () => void, y: (x?: string | undefined) => void) => void +>f3 : (x: () => void, y: (x?: string) => void) => void >x : () => void ->y : (x?: string | undefined) => void +>y : (x?: string) => void >x : string | undefined let f = !!true ? x : y; // (x?: string) => void @@ -88,10 +88,10 @@ function f3(x: () => void, y: (x?: string) => void) { } function f4(x: (x: string | undefined) => void, y: (x?: string) => void) { ->f4 : (x: (x: string | undefined) => void, y: (x?: string | undefined) => void) => void +>f4 : (x: (x: string | undefined) => void, y: (x?: string) => void) => void >x : (x: string | undefined) => void >x : string | undefined ->y : (x?: string | undefined) => void +>y : (x?: string) => void >x : string | undefined let f = !!true ? x : y; // (x?: string) => void @@ -114,10 +114,10 @@ function f4(x: (x: string | undefined) => void, y: (x?: string) => void) { } function f5(x: (x: string | undefined) => void, y: (x?: 'hello') => void) { ->f5 : (x: (x: string | undefined) => void, y: (x?: "hello" | undefined) => void) => void +>f5 : (x: (x: string | undefined) => void, y: (x?: 'hello') => void) => void >x : (x: string | undefined) => void >x : string | undefined ->y : (x?: "hello" | undefined) => void +>y : (x?: 'hello') => void >x : "hello" | undefined let f = !!true ? x : y; // (x?: 'hello') => void @@ -140,10 +140,10 @@ function f5(x: (x: string | undefined) => void, y: (x?: 'hello') => void) { } function f6(x: (x: 'hello' | undefined) => void, y: (x?: string) => void) { ->f6 : (x: (x: 'hello' | undefined) => void, y: (x?: string | undefined) => void) => void +>f6 : (x: (x: 'hello' | undefined) => void, y: (x?: string) => void) => void >x : (x: 'hello' | undefined) => void >x : "hello" | undefined ->y : (x?: string | undefined) => void +>y : (x?: string) => void >x : string | undefined let f = !!true ? x : y; // (x: 'hello' | undefined) => void @@ -173,10 +173,10 @@ type A = { } type B = { ->B : { f(x?: string | undefined): void; g(): void; } +>B : { f(x?: string): void; g(): void; } f(x?: string): void; ->f : (x?: string | undefined) => void +>f : (x?: string) => void >x : string | undefined g(): void; @@ -227,9 +227,9 @@ declare const val: ReturnVal; >val : ReturnVal function run(options: { something?(b?: string): void }) { ->run : (options: { something?(b?: string | undefined): void; }) => void ->options : { something?(b?: string | undefined): void; } ->something : ((b?: string | undefined) => void) | undefined +>run : (options: { something?(b?: string): void; }) => void +>options : { something?(b?: string): void; } +>something : ((b?: string) => void) | undefined >b : string | undefined const something = options.something ?? val.something; diff --git a/tests/baselines/reference/variadicTuples1.types b/tests/baselines/reference/variadicTuples1.types index 3aa03e67b84b9..64a25d510c047 100644 --- a/tests/baselines/reference/variadicTuples1.types +++ b/tests/baselines/reference/variadicTuples1.types @@ -1349,13 +1349,13 @@ const b = a.bind("", 1); // Desc<[boolean], object> // Repro from #39607 declare function getUser(id: string, options?: { x?: string }): string; ->getUser : (id: string, options?: { x?: string | undefined; } | undefined) => string +>getUser : (id: string, options?: { x?: string;}) => string >id : string >options : { x?: string | undefined; } | undefined >x : string | undefined declare function getOrgUser(id: string, orgId: number, options?: { y?: number, z?: boolean }): void; ->getOrgUser : (id: string, orgId: number, options?: { y?: number | undefined; z?: boolean | undefined; } | undefined) => void +>getOrgUser : (id: string, orgId: number, options?: { y?: number; z?: boolean;}) => void >id : string >orgId : number >options : { y?: number | undefined; z?: boolean | undefined; } | undefined diff --git a/tests/cases/conformance/declarationEmit/leaveOptionalParameterAsWritten.ts b/tests/cases/conformance/declarationEmit/leaveOptionalParameterAsWritten.ts new file mode 100644 index 0000000000000..f22262cb82c11 --- /dev/null +++ b/tests/cases/conformance/declarationEmit/leaveOptionalParameterAsWritten.ts @@ -0,0 +1,22 @@ +// @module: esnext +// @outDir: dist +// @declaration: true +// @emitDeclarationOnly: true +// @strictNullChecks: true + +// @Filename: a.ts +export interface Foo {} + +// @Filename: b.ts +import * as a from "./a"; +declare global { + namespace teams { + export namespace calling { + export import Foo = a.Foo; + } + } +} + +// @Filename: c.ts +type Foo = teams.calling.Foo; +export const bar = (p?: Foo) => {} \ No newline at end of file