#VS Code is not flagging one specific Typescript error but seems fine with all others?
12 messages · Page 1 of 1 (latest)
type tFruitObjectMap = {
"apple": number,
"orange": string,
"pear": boolean,
}
type tFruitObjectStates = {
[T in tFruitKeys]: tFruitObjectMap[T]
}
const fruitStates: tFruitObjectStates = {
"apple": 1,
"orange": "foo",
"pear": true,
}
function testFunction<T extends tFruitKeys>(table: T) {
/**
* THIS is fine and correct. It gives no errors and SHOULDN'T give any errors, either.
*/
console.log(fruitStates[table])
/**
* THIS should give the following error:
* Element implicitly has an 'any' type because expression of type '"any random string"' can't be used to index type 'tFruitObjectStates'.
* Property 'any random string' does not exist on type 'tFruitObjectStates'.(7053)
*/
console.log(fruitStates["any random string"])
/**
* This SHOULD error and it DOES.
* Type 'false' cannot be used as an index type (so typescript is definitely working here)
*/
console.log(fruitStates[false])
}
The issue is with fruitStates["any random string"]
Here's my settings json
"workbench.colorTheme": "Default Dark+",
"explorer.confirmDragAndDrop": false,
"git.autofetch": true,
"javascript.updateImportsOnFileMove.enabled": "always",
"explorer.confirmDelete": false,
"editor.minimap.enabled": false,
"js/ts.implicitProjectConfig.checkJs": true,
"jsonColorToken.languages": [
"typescript", "javascript", "css", "scss",
"json",
"jsonc"
],
"typescript.preferences.importModuleSpecifier": "relative",
"mui-snippets.importPaths": "second level",
"typescript.updateImportsOnFileMove.enabled": "always",
"chat.commandCenter.enabled": false,
"geminicodeassist.project": "",
"geminicodeassist.enable": false,
"javascript.preferences.importModuleSpecifier": "relative",
"git.ignoreMissingGitWarning": true,
"githubIssues.authToken": "CENSORED",
"githubIssues.repoOwner": "CENSORED",
"githubIssues.repoName": "CENSORED",
"chat.disableAIFeatures": true,
"typescript.format.placeOpenBraceOnNewLineForFunctions": true,
"typescript.tsserver.experimental.enableProjectDiagnostics": true,
"[typescript]": {
}
}```
@unreal zealot What's your tsconfig.json? That's more relevant than vscode settings
I have a tsconfig.json:
"files": [],
"references": [{ "path": "./tsconfig.node.json" }, { "path": "./tsconfig.web.json" }]
}
tsconfig.node.json:
{
"extends": "@electron-toolkit/tsconfig/tsconfig.node.json",
"include": ["electron.vite.config.*", "src/main/**/*", "src/preload/**/*", "src/shared/**/*", "src/renderer/src/global.d.ts", "src/renderer/src/ZodClasses.ts"],
"compilerOptions": {
"composite": true,
"types": ["electron-vite/node"]
}
}
and a tsconfig.web.json:
"extends": "@electron-toolkit/tsconfig/tsconfig.web.json",
"include": [
"src/renderer/src/env.d.ts",
"src/renderer/src/**/*",
"src/shared/**/*",
"src/renderer/src/**/*.tsx",
"src/shared/Classes.ts",
"src/main/databaseInit.ts",
"src/main/createTables.ts",
"src/main/updateTables.ts",
"src/renderer/src/shared/Classes.ts",
],
"compilerOptions": {
"composite": true,
"jsx": "react-jsx",
"baseUrl": ".",
"paths": {
"@renderer/*": [
"src/renderer/src/*"
]
}
}
}
@unreal zealot Looks like electron-toolkit's tsconfig sets noImplicitAny: false, which is the rule that catches that issue
The CDN for everything on npm
It'll also probably allow stuff like function foo(thisIsAny) {} which would also be an issue.
I don't know why they'd turn strict: true, but turn that specific strictness rule off; you can probably override it back to true in your config, but I'm not sure why they did that in the first place, may be a reason
Wow yeah that's done it, thank you so much! You're amazing.