1/* 2* Copyright (c) Microsoft Corporation. All rights reserved. 3* Copyright (c) 2023 Huawei Device Co., Ltd. 4* Licensed under the Apache License, Version 2.0 (the "License"); 5* you may not use this file except in compliance with the License. 6* You may obtain a copy of the License at 7* 8* http://www.apache.org/licenses/LICENSE-2.0 9* 10* Unless required by applicable law or agreed to in writing, software 11* distributed under the License is distributed on an "AS IS" BASIS, 12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13* See the License for the specific language governing permissions and 14* limitations under the License. 15* 16* This file has been modified by Huawei to verify type inference by adding verification statements. 17*/ 18 19// === tests/cases/compiler/circularlySimplifyingConditionalTypesNoCrash.ts === 20declare function AssertType(value:any, type:string):void; 21type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>; 22 23type Shared< // Circularly self constraining type, defered thanks to mapping 24 InjectedProps, 25 DecorationTargetProps extends Shared<InjectedProps, DecorationTargetProps> 26 > = { 27 [P in Extract<keyof InjectedProps, keyof DecorationTargetProps>]: InjectedProps[P] extends DecorationTargetProps[P] ? DecorationTargetProps[P] : never; 28 }; 29 30interface ComponentClass<P> { 31 defaultProps?: Partial<P>; // Inference target is also mapped _and_ optional 32} 33 34interface InferableComponentEnhancerWithProps<TInjectedProps, TNeedsProps> { 35 <P extends Shared<TInjectedProps, P>>( 36 component: ComponentClass<P> 37 ): ComponentClass<Omit<P, keyof Shared<TInjectedProps, P>> & TNeedsProps> & { WrappedComponent: ComponentClass<P> } 38} // Then intersected with and indexed via Omit and & 39 40interface Connect { // Then strictly compared with another signature in its context 41 <TStateProps, TOwnProps>( 42 mapStateToProps: unknown, 43 ): InferableComponentEnhancerWithProps<TStateProps, TOwnProps>; 44 45 <TDispatchProps, TOwnProps>( 46 mapStateToProps: null | undefined, 47 mapDispatchToProps: unknown, 48 mergeProps: null | undefined, 49 options: unknown 50 ): InferableComponentEnhancerWithProps<TDispatchProps, TOwnProps>; 51} 52 53declare let connect: Connect; 54AssertType(connect, "Connect"); 55 56const myStoreConnect: Connect = function( 57AssertType(myStoreConnect, "Connect"); 58AssertType(function( mapStateToProps?: any, mapDispatchToProps?: any, mergeProps?: any, options: unknown = {},) { return connect( mapStateToProps, mapDispatchToProps, mergeProps, options, );}, "<TStateProps, TOwnProps>(?any, ?any, ?any, ?unknown) => InferableComponentEnhancerWithProps<TStateProps, Omit<P, Extract<keyof TStateProps, keyof P>> & TOwnProps>"); 59 60 mapStateToProps?: any, 61AssertType(mapStateToProps, "any"); 62 63 mapDispatchToProps?: any, 64AssertType(mapDispatchToProps, "any"); 65 66 mergeProps?: any, 67AssertType(mergeProps, "any"); 68 69 options: unknown = {}, 70AssertType(options, "unknown"); 71AssertType({}, "{}"); 72 73) { 74AssertType(connect( mapStateToProps, mapDispatchToProps, mergeProps, options, ), "InferableComponentEnhancerWithProps<TStateProps, Omit<P, Extract<keyof TStateProps, keyof P>> & TOwnProps>"); 75AssertType(connect, "Connect"); 76 return connect( 77 78 mapStateToProps, 79AssertType(mapStateToProps, "any"); 80 81 mapDispatchToProps, 82AssertType(mapDispatchToProps, "any"); 83 84 mergeProps, 85AssertType(mergeProps, "any"); 86 87 options, 88AssertType(options, "unknown"); 89 90 ); 91}; 92 93export {}; 94 95 96