Not Duplicate
This is not the duplicate question because here my issue is in index signature not in object literal or type annotation. Please read carefully my question.
In few days I started to learn TypeScript. While when I reached at topic duck typing. I am confused in some of its basic rules.
Overview
In below code I have complete understanding. That, why we are using duck typing.
//Object declaration & initialization
let obj1 : {id:number, name:string};
obj1 = {id: 1,name: "Ahmer Ali Ahsan"};
//Error, missing property name
obj1 = {id:1};
let obj2 : {id:number, [obj2: string]:any};
obj2 = {id: 1, firstname: "Ahmer"};
//We add new property members due to index signatures
obj2 = {id: 2, firstname: "Ahmer", middlename:"Ali", lastname: "Ahsan"};
//We erase property members due to index signatures
obj2 = {id:2};
Problem
I have a question that if TypeScript is a type safety language. Then in below code I have all parameter types are number and index signature type is also a number.
let obj3 : {id:number, [obj3: number]: number};
obj3 = {id: 1, rollno: "Why error is not showing here?"};
Question
Why is there no error due to the [obj: number]: number index signature when I assign rollno to a string value?
Please explain briefly with your answers. If my concepts of index signature is still not clear.