IssueRaiser

Strict null checks for Map members

<!-- BUGS: Please use this template. --> <!-- QUESTIONS: This is not a general support forum! Ask Qs at http://stackoverflow.com/questions/tagged/typescript --> <!-- SUGGESTIONS: See https://github.com/Microsoft/TypeScript-wiki/blob/master/Writing-Good-Design-Proposals.md --> **TypeScript Version:** 2.0.0-beta **Code** ``` ts export interface INode { type: string; parentNode?: INode; } export interface IIdentifierNode extends INode { name: string; } public static isIdentifierNode (node: INode): node is IIdentifierNode { return node.type === NodeType.Identifier; } var namesMap = new Map<string, string>(); // main part if (Nodes.isIdentifierNode(node) && namesMap.has(node.name)) { node.name = namesMap.get(node.name); //`Type 'string | undefined' is not assignable to type 'string'.` } ``` **Expected behavior:** No errors **Actual behavior:** `Type 'string | undefined' is not assignable to type 'string'.` Looks like here no TypeGuards for Maps?

Posted by sanex3339 on Jul 11, 2016, 7:25 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.5,000 issues0 comments

support (Software)

Strict null checks for Map members

sanex3339Jul 11, 2016, 7:25 PM

<!-- BUGS: Please use this template. --> <!-- QUESTIONS: This is not a general support forum! Ask Qs at http://stackoverflow.com/questions/tagged/typescript --> <!-- SUGGESTIONS: See https://github.com/Microsoft/TypeScript-wiki/blob/master/Writing-Good-Design-Proposals.md --> **TypeScript Version:** 2.0.0-beta **Code** ``` ts export interface INode { type: string; parentNode?: INode; } export interface IIdentifierNode extends INode { name: string; } public static isIdentifierNode (node: INode): node is IIdentifierNode { return node.type === NodeType.Identifier; } var namesMap = new Map<string, string>(); // main part if (Nodes.isIdentifierNode(node) && namesMap.has(node.name)) { node.name = namesMap.get(node.name); //`Type 'string | undefined' is not assignable to type 'string'.` } ``` **Expected behavior:** No errors **Actual behavior:** `Type 'string | undefined' is not assignable to type 'string'.` Looks like here no TypeGuards for Maps?

Comments (0)

No comments yet. Start the discussion.

Comment on this issue