Typescript incorrect types
See original GitHub issueDoes this issue occur when all extensions are disabled?: Yes
- VS Code Version: 1.68.1
- OS Version: Windows_NT x64 10.0.19044
Steps to Reproduce:
- Open VSCode and create a new text file (Ctrl+N)
- Set the language to Typescript
- Paste this code into it:
export interface Foo {
objs: { id(): string; }[];
}
export class Test {
private foo: Foo | null = null;
doSomething(ids: Record<string, boolean>) {
if (!this.foo) return;
for (let i = 0; i < this.foo.objs.length; i++) {
const obj = this.foo.objs[i];
const objId = obj.id();
if (!ids[objId]) return;
}
}
}
- The type of
obj
on line 12 is incorrectly identified asany
rather than{ id(): string; }
. This can cause errors in a project withnoImplicitAny
set totrue
- The Typescript compiler compiles the code without issue, so I believe this is a bug only with the intellisense.
Issue Analytics
- State:
- Created a year ago
- Comments:11 (3 by maintainers)
Top Results From Across the Web
How to overwrite incorrect TypeScript type definition installed ...
Say that I want to use dotenv module in my TypeScript project and install its .d.ts using npm install @types/dotenv --save . Then...
Read more >TypeScript Done Wrong - OpenReplay Blog
TypeScript Done Wrong · Overusing the any type · Using the Function type instead of specifying the signature · Open Source Session Replay...
Read more >Documentation - Do's and Don'ts - TypeScript
❌ Don't ever use the types Number , String , Boolean , Symbol , or Object These types refer to non-primitive boxed objects...
Read more >Typescript imports are incorrectly imported from `@types/`
What steps will reproduce the problem? Use jsx in a tsx file. Get the prompt to import react. Import react; WS inserts import...
Read more >Surviving the TypeScript Ecosystem — Part 4 - Medium
Surviving the TypeScript Ecosystem — Part 4: Working with Types and Type ... Now we can remove our incorrect module definition for lodash...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The circularity is this:
obj
? It’s determined by its initializer, what is its type?this.foo.objs[0]
. What is its type?this.foo
is initialized or not. Is it?this.foo
changes type. Is it possible to enter the loop a second time?ids[objId]
. Is this always truthy?objId
is a statically-knowable index. Is it?obj.id
. What’s the type of that?obj
. What is the type of obj? <-- ♻ this is the question being askedThis is just an educated guess, but I’m assuming that obtaining
objId
from a function short-circuits the check here: