You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incorrect type inference with indexer leads to TS2322 #28602
class One
{
}
class Two
{
public prop: One | null = null;
}
const aTwo = new Two();
aTwo.prop = null; // makes TypeScript infer that the type of aTwo.prop is null but only when using indexer syntax which...
aTwo["prop"] = new One(); // results in TS2322: Type 'One' is not assignable to type null on this line
aTwo.prop = new One(); // this line is however fine
Also...
aTwo.prop = null; // commenting this out or
// aTwo.prop = new One(); // uncommenting this (when it's place before)
aTwo["prop"] = new One(); // makes the TS2322 error on this line go away
Expected behavior: aTwo["prop"] = new One(); should not result in an error
Actual behavior: It results in TS2322.
Playground Link:
Related Issues: The title of this sounds similar to #17011 but this is different and this is new in TypeScript 3.1 (AFAICT) and wasn't an issue in TypeScript 3.0.
Ah.. thanks for the instantaneous reply. Yes, this does sound like a duplicate of #27412 but unfortunately, its title didn't have the keywords I looked for.
Activity
ajafff commentedon Nov 19, 2018
Should already be fixed by #27574 in 3.2.0-rc
Manish3177 commentedon Nov 19, 2018
Ah.. thanks for the instantaneous reply. Yes, this does sound like a duplicate of #27412 but unfortunately, its title didn't have the keywords I looked for.
typescript-bot commentedon Dec 12, 2018
This issue has been marked as a duplicate and has seen no activity in the last day. It has been closed automatic house-keeping purposes.