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
interfaceStudent{name: string};// current: Error thrown when using i?.name because ts don't know what the keyof i will to beconstisStudent=(i: unknown): i is Student=>typeofi?.name==='string';
but in fact, optional chaining is designed for safety get the value of var, so an optional chaining for unknown types should be unknown too:
declareconsti1: unknown;consti2=i1?.aaa;// optional chaining for unknown i1typeT=typeofi2;// T should be unknown too
🔍 Search Terms
List of keywords you searched for before creating this issue. Write them down here so that others can find this suggestion more easily and help provide feedback.
✅ Viability Checklist
My suggestion meets these guidelines:
This wouldn't be a breaking change in existing TypeScript/JavaScript code
This wouldn't change the runtime behavior of existing JavaScript code
This could be implemented without emitting different JS based on the types of the expressions
This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
One: for type predicate, avoiding the usage of any
interfaceFile{fileId: string;}interfaceFolder{folderId: string;}constisFile=(i: unknown): i is File=>typeofi?.fileId==='string';constisFolder=(i: unknown): i is Folder=>typeofi?.folderId==='string';// better than any:constisFile=(i: any): i is File=>typeofi?.fileId==='string';
Uh oh!
There was an error while loading. Please reload this page.
Suggestion
but in fact, optional chaining is designed for safety get the value of var, so an optional chaining for unknown types should be unknown too:
🔍 Search Terms
List of keywords you searched for before creating this issue. Write them down here so that others can find this suggestion more easily and help provide feedback.
✅ Viability Checklist
My suggestion meets these guidelines:
⭐ Suggestion
📃 Motivating Example
One: for type predicate, avoiding the usage of any
Two: a better unknown types processing experience
💻 Use Cases
The text was updated successfully, but these errors were encountered: