Skip to content

The "?" operator would be forbidden before the "!" operatorΒ #63191

@Chklang

Description

@Chklang

πŸ”Ž Search Terms

typescript ? operator with !

πŸ•— Version & Regression Information

Versions tested : 5.9.3 and 5.6.3

⏯ Playground Link

No response

πŸ’» Code

interface A {
  b?: string;
}
function tt(v?: A) {
  const str: string = v?.b!;
  return str;
}
console.log("Value : ", tt());

πŸ™ Actual behavior

The result is : "Value : undefined"

πŸ™‚ Expected behavior

Compilator must refuse to combine ? before an !

v?.b! must to be refuse by typescript compilator. We must do "v!.b!" to have the good type.

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeclinedThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions