I'll proceed with the blog assuming you have previously worked with JavaScript. Knowing JavaScript would have you catch on to TypeScript concepts ...
For further actions, you may consider blocking this person and/or reporting abuse
TypeScript is not a superset of JavaScript. This perfectly valid JS throws an error in TS:
it error because it does not pass the type check (that is the purpose of typescript: type check)
doesn't mean typescript is not super set of javascript
a valid JS code that does not pass typescript type check only throw error on compilation but not run time
simply expect the error and you can run the code
playground
Instead using
Add a dynamic type and defined possible types for value
the reason i use
// @ts-expect-erroris because I want to show that untyped code is a valid code in TSalso
[key: number | string]in unnecessary because it is equivalent to[key: strting]dev.to/tylim88/typescript-caveat-1...
True Sorry my mistake. Object keys is always a string.
ts-expect-error will report if there is no error.
Unused '@ts-expect-error' directiveWhich can be solved with
// @ts-ignoreItβs a choice of course.
which is why you should only use it on line that has error
normally
// @ts-ignoreis not desirable because it is not granular, it will just ignore everything and will ignore thing that you don't want to ignore (but is ok in this case)and because of granularity
// @ts-expect-erroris very useful in type testingobject key can be numeric, it will be converted to string on runtime
type wise key type of both
{[x:string]:unknown}and{[x:string | number ]:unknown}arestring | numberwhich is why I said it is unnecessary, not incorrect
I wouldnβt recommended to install TS global, I would recommend to install it as dependacy. So you will be sure all teammembers will use the same TS version
You can use is as follow with npx