typescript, when declare variable and object inside class method, why only primitive type need...

Discussão em 'Angular' iniciado por user1169587, Outubro 18, 2024.

  1. user1169587

    user1169587 Guest

    For the following example

    export class AppComponent implements OnInit {
    driveTypes: string[];
    vehicleTypes: string[];
    vehicle: Vehicle;
    test2:string;
    testObj2 :{key2:'value2'};

    method1(){
    let test1:string;
    let test2 = 'abc';
    test3:string; // 'string' only refers to a type, but is being used as a value here.(2693)
    test4 = 'def'; // Cannot find name 'test4'. Did you mean 'test1'?(2552)
    testObj : {key1:'value1'};
    let testObj2 : {key3:'value3'};
    }


    Inside method1(), why test3, test4 has error and must use let keyword like

    let test1:string;
    let test2 = 'abc';


    but

    testObj : {key1:'value1'};


    has no any error?

    Continue reading...

Compartilhe esta Página