Skip to content

Instantly share code, notes, and snippets.

@beattyml1
Last active October 20, 2023 17:52
Show Gist options
  • Save beattyml1/a02a0184930544b301ec104109c4fd95 to your computer and use it in GitHub Desktop.
Save beattyml1/a02a0184930544b301ec104109c4fd95 to your computer and use it in GitHub Desktop.
Web Storm TypeScript Bug
{
"name": "webstorm-issues",
"version": "1.0.0",
"dependencies": {
"typescript": "^5.2.2"
}
}

In the above file the first two types work in both ts compiler and webstorm. The final type works in ts compiler but fails in Web Storm

type MyTypeWorks1<T extends {[k: string]: any}> = {
[K in keyof T]: T[K]
}
let instance1: MyTypeWorks1<{test:string}> = {test: ''};
let val1 = instance1.test; // Autocomplete works, doesn't highlight as error
type MyTypeWorks2<T extends {[k: string]: any}> = {
[K in Uppercase<keyof T & string>]: any
}
let instance2: MyTypeWorks2<{test:string}> = {TEST: ''};
let val2 = instance2.TEST; // Autocomplete works, doesn't highlight as error
type MyTypeDoesNotWork<T extends {[k: string]: any}> = {
[K in Uppercase<keyof T & string>]: T[K]
}
let nonWorkingInstance: MyTypeDoesNotWork<{test: string}> = {TEST: ''};
let val3 = nonWorkingInstance.TEST; // Fails to autocomplete
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"sourceMap": true
},
"exclude": [
"node_modules"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment