TypeScript Version: 3.8.3
Search Terms:
Property does not exist on type
Code
Below is valid Javascript however it does not compile with TypeScript and there is no tsconfig.json setting to enable it to work:
let v = {pet: "cat", friend: "Joe"};
v.toy = "hammer";
This is a definition of subset: "a set which includes another set or sets.". The above code comes from Javascript but it can't work in TypeScript without manually adding TypeScript to it via any or // @ts-ignore.
This is a real problem for me right now because I need to port a number of Javascript npm packages to deno TypeScript. As it is now there are hundreds of places in code I need to manually change to make this work because TypeScript isn't actually a superset. If it only had additional configuration variables for tsconfig.json that allowed regular valid javascript it would be a superset.
I need to convert the Javascript to Typescript because the vscode extension that I am using and that is available (https://marketplace.visualstudio.com/items?itemName=axetroy.vscode-deno) tells me where the deno and node.js differences are that I need to handle, but it only works with TypeScript so I need to convert it to TypeScript.
The most frequent error I am getting that I want to suppress globally (but currently can't) is this one: Property 'toy' does not exist on type '{ pet: string; friend: string; }'.
Expected behavior:
I expect there to be more settings available for tsconfig.json to all me to use valid javascript without having to manually add TypeScript.
and there is no tsconfig.json setting to enable it to work
"noEmitOnError": false
There are also various ways you can type v to make sense and satisfy TypeScript at the same time. I can't say for sure what's best for you without a more realistic scenario, but some possibilities:
interface Kid { pet: string, friend: string, toy?: string }
type BagOJunk = { [key: string]: string }
@nmain Thank you for pointing out "noEmitOnError": false. I was not aware of how this worked. With this I see that TypeScript really is a superset of Javascript. I was wrong.
It would still be nice if there was a way to globally turn off these errors and only show javascript errors.
I understand the examples you gave me but those are manual solutions. I'm looking for a global settings so I don't have to manually write the kind of code you gave 100 times.
You can add // @ts-ignore in head of file and no type error will show.
You are looking for a "global setting" to disable TypeScript. That's called not using TypeScript...
There's a lot of knobs that you can use to make migration easier, some which have been pointed out:
strict set to false (already the default)noEmitOnError set to false (already the default)any// @ts-ignore comments to suppress error messages// @ts-expect-error comments coming up in 3.9 (maybe less relevant in this situation)And even further in .js files:
allowJs to compile .js files without reporting errorscheckJs set to false to disable errors when allowJs is on (already the default)// @ts-check comments in .js files to turn on checking for an entire file, so that you can migrate a file at a time// @ts-nocheck comments in .js files to turn off checking for an entire file
Most helpful comment
You are looking for a "global setting" to disable TypeScript. That's called not using TypeScript...