Quantcast
Channel: YouTrackReSharper (RSRP) - Bug and Issue Tracker
Viewing all articles
Browse latest Browse all 106942

RSRP-466133: Incorrect handling of weak types

$
0
0
Reporter Andrew Mayorov (xorets.1) Andrew Mayorov (xorets.1)
Created Sep 4, 2017 4:04:07 PM
Updated Apr 9, 2018 3:26:23 PM
Subsystem TypeScript
Assignee Nikita Popov (poksh)
Priority Critical
State Fixed In Branch
Type Bug
Fix version 2018.1
Affected versions 2017.2
Fixed In Version ReSharper 2018.1 EAP 7
VsVersion All Versions
If I have a weak type (only optional fields) that also has a "wildcard" indexer (no matter if it is inherited or declared on the type itself), then I can't cast an object to the weak type, unless the object has any of optional fields declared in the weak type. It conflicts with the behavior of TS compiler, which allows such casts if we have "wildcard" indexer declared.

interface ITestA {
[name: string]: any; // This "wildcard" indexer is necessary for the cast to be legal
}

var a: ITestA = { a: "a", b: 3 }; // OK

interface ITestB extends ITestA {
optionalField?: string;
}

var b: ITestB = { a: "a", b: 3 }; // Error: has no properties in common
var b2: ITestB = { a: "a", b: 3, optionalField: null }; // OK

This behavior appeared recently in version 2017.2. I guess after adding the support for TS 2.4. This is quite major, because now a lot of valid code gets rendered as invalid.

Viewing all articles
Browse latest Browse all 106942

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>