A Tuple can be made immutable by applying the `readonly` modifier, preventing any changes to its values. Example: type Person = readonly [string, number, string]; let person: Person = ['John Smith', 45, 'Male']; person.push('some value'); // Error: Property 'push' does not exist on type 'Person'.
Summary: Tuples: Define a fixed-length array where each element can have a different type. Usage: Useful for representing structured data where the order and types of elements are important (e.g., returning multiple values from a function).
type User = [number,string] let usr1:User = [101,"chiranjeeb"] usr1.push(true) console.log(usr1) this is not allowing me to do push operations Error :- first.ts:12:11 - error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'.
Hi Sir, one query as we know array is group same datatypes, but now by declaring datatypes we are able to pass different datatype elements to same array.. please tell how it is?
Learn full stack developer with live classes:
hc.lco.dev/jscamp2
I know all this stuff, still i watch the full video, because it is fun to watch your video and the way you teach. 😊
A Tuple can be made immutable by applying the `readonly` modifier, preventing any changes to its values.
Example:
type Person = readonly [string, number, string];
let person: Person = ['John Smith', 45, 'Male'];
person.push('some value'); // Error: Property 'push' does not exist on type 'Person'.
SUPER topic HITESH SIR...😀😀😀
Summary:
Tuples: Define a fixed-length array where each element can have a different type.
Usage: Useful for representing structured data where the order and types of elements are important (e.g., returning multiple values from a function).
You are the "Virat Kohli" of Coding Community.
Now the push is showing me error that => type 'boolean' is not assignable to parameter of type 'string | number' maybe that issue has been solved!
Yeah seems that they have fixed this issue now I am getting an error while using push and unshift
Always Great to Learn From You Sir😊
Love you sir you are just amazing
type User = [number,string]
let usr1:User = [101,"chiranjeeb"]
usr1.push(true)
console.log(usr1)
this is not allowing me to do push operations
Error :- first.ts:12:11 - error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'.
true is of type boolean which is neither a number nor a string. Please read the error carefully.
Yes, if you pass the number or string than only you will able to do array methods.
Yes , even I watched video and there it's working fine even when I implemented it was showing same error.
that's actually good its preventing us from pushing beyond its limits.
Awesome ❤❤❤❤
nice explanation !
We can fix that issues with tuples using readonly keyword but how tf I am gonna remember it everytime while creating applications 😭😭
Thank you sir....
I guess U have become bhrmastr of coders sir. Every warrior(coder) wanted n loves u bt wanted to keep u secret for future combat reasons.
awesome
Hi Sir, one query as we know array is group same datatypes, but now by declaring datatypes we are able to pass different datatype elements to same array.. please tell how it is?
I think you should learn javascript first
Thank you :)
rgb stands for? in 6th line
Please share SO question link
Hello sir can you please make this series in Hindi Language.
Nice 🥰🥰
now the push is showing the error
this is not what a "tuple" is, But ok nice clickbait
♥️♥️♥️
cool
day 2