File: reactDefaultPropsInferenceSuccess.errors.txt

package info (click to toggle)
node-typescript 3.3.3333-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 324,548 kB
  • sloc: makefile: 6; sh: 3
file content (93 lines) | stat: -rw-r--r-- 5,174 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
tests/cases/compiler/reactDefaultPropsInferenceSuccess.tsx(27,36): error TS2322: Type '(value: string) => void' is not assignable to type '"a" | "b" | ((value: string) => boolean) | undefined'.
  Type '(value: string) => void' is not assignable to type '(value: string) => boolean'.
    Type 'void' is not assignable to type 'boolean'.
tests/cases/compiler/reactDefaultPropsInferenceSuccess.tsx(43,41): error TS2322: Type '(value: string) => void' is not assignable to type '"a" | "b" | ((value: string) => boolean) | undefined'.
  Type '(value: string) => void' is not assignable to type '(value: string) => boolean'.
    Type 'void' is not assignable to type 'boolean'.
tests/cases/compiler/reactDefaultPropsInferenceSuccess.tsx(64,37): error TS2322: Type '(value: string) => void' is not assignable to type '(value: string) => boolean'.
  Type 'void' is not assignable to type 'boolean'.


==== tests/cases/compiler/reactDefaultPropsInferenceSuccess.tsx (3 errors) ====
    /// <reference path="/.lib/react16.d.ts" />
    
    import React from 'react';
    
    interface BaseProps {
      when?: ((value: string) => boolean) | "a" | "b";
      error?: boolean;
    }
    
    interface Props extends BaseProps {
    }
    
    class FieldFeedback<P extends Props = BaseProps> extends React.Component<P> {
      static defaultProps = {
        when: () => true
      };
    
      render() {
        return <div>Hello</div>;
      }
    }
    
    // OK
    const Test1 = () => <FieldFeedback when={value => !!value} />;
    
    // Error: Void not assignable to boolean
    const Test2 = () => <FieldFeedback when={value => console.log(value)} />;
                                       ~~~~
!!! error TS2322: Type '(value: string) => void' is not assignable to type '"a" | "b" | ((value: string) => boolean) | undefined'.
!!! error TS2322:   Type '(value: string) => void' is not assignable to type '(value: string) => boolean'.
!!! error TS2322:     Type 'void' is not assignable to type 'boolean'.
!!! related TS6500 tests/cases/compiler/reactDefaultPropsInferenceSuccess.tsx:6:3: The expected type comes from property 'when' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<FieldFeedback<Props>> & Pick<Readonly<{ children?: ReactNode; }> & Readonly<Props>, "children" | "error"> & Partial<Pick<Readonly<{ children?: ReactNode; }> & Readonly<Props>, "when">> & Partial<Pick<{ when: () => boolean; }, never>>'
    
    class FieldFeedbackBeta<P extends Props = BaseProps> extends React.Component<P> {
      static defaultProps: BaseProps = {
        when: () => true
      };
    
      render() {
        return <div>Hello</div>;
      }
    }
    
    // OK
    const Test1a = () => <FieldFeedbackBeta when={value => !!value} error>Hah</FieldFeedbackBeta>;
    
    // Error: Void not assignable to boolean
    const Test2a = () => <FieldFeedbackBeta when={value => console.log(value)} error>Hah</FieldFeedbackBeta>;
                                            ~~~~
!!! error TS2322: Type '(value: string) => void' is not assignable to type '"a" | "b" | ((value: string) => boolean) | undefined'.
!!! error TS2322:   Type '(value: string) => void' is not assignable to type '(value: string) => boolean'.
!!! error TS2322:     Type 'void' is not assignable to type 'boolean'.
!!! related TS6500 tests/cases/compiler/reactDefaultPropsInferenceSuccess.tsx:6:3: The expected type comes from property 'when' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<FieldFeedbackBeta<Props>> & Pick<Readonly<{ children?: ReactNode; }> & Readonly<Props>, "children"> & Partial<Pick<Readonly<{ children?: ReactNode; }> & Readonly<Props>, "when" | "error">> & Partial<Pick<BaseProps, never>>'
    
    interface MyPropsProps extends Props {
      when: (value: string) => boolean;
    }
    
    class FieldFeedback2<P extends MyPropsProps = MyPropsProps> extends FieldFeedback<P> {
      static defaultProps = {
        when: () => true
      };
    
      render() {
        this.props.when("now"); // OK, always defined
        return <div>Hello</div>;
      }
    }
    
    // OK
    const Test3 = () => <FieldFeedback2 when={value => !!value} />;
    
    // Error: Void not assignable to boolean
    const Test4 = () => <FieldFeedback2 when={value => console.log(value)} />;
                                        ~~~~
!!! error TS2322: Type '(value: string) => void' is not assignable to type '(value: string) => boolean'.
!!! error TS2322:   Type 'void' is not assignable to type 'boolean'.
!!! related TS6500 tests/cases/compiler/reactDefaultPropsInferenceSuccess.tsx:46:3: The expected type comes from property 'when' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<FieldFeedback2<MyPropsProps>> & Pick<Readonly<{ children?: ReactNode; }> & Readonly<MyPropsProps>, "children" | "error"> & Partial<Pick<Readonly<{ children?: ReactNode; }> & Readonly<MyPropsProps>, "when">> & Partial<Pick<{ when: () => boolean; }, never>>'
    
    // OK
    const Test5 = () => <FieldFeedback2 />;