ajitid / fzf-for-js

Do fuzzy matching using FZF algorithm in JavaScript

Home Page:https://fzf.netlify.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[question] What does the postfix ! do?

dotnetCarpenter opened this issue · comments

Hi, congratz on being on javascript weekly.

I skimmed the source and found str.split("").map((s) => s.codePointAt(0)!);.

What is the postfix ! for? I tried to copy the line and are getting a syntax error in nodejs REPL.
Is it a typescript thing?

Cheers!

commented

Hey! Thanks, only yesterday I found out that this library is mentioned in the newsletter.

What is the postfix ! for? ... Is it a typescript thing?

Yes, this is a TypeScript thing. codePointAt can return undefined if it doesn't find a character at that index. By appending ! we are telling TypeScript that it is safe to assume that the returned value from codePointAt is a non-null, non-undefined value.

Try hovering over strOrNull and onlyStr in this TS playground to see how it works.

Hope that helps!