Comments (2)
Without an actually runnable reproduction it's impossible to verify, but it looks to me like the type-checking error is correct per your types. user.contracts.length > 0
is not a safe expression to execute since user.contracts
is potentially undefined
(declared optional: contracts?: Array<AnyContractDTO>
), and nothing guards its access.
from angular.
I tried again. - it definitely doesn't work
This doesn't work
@if(user().contracts && user().contracts?.length > 0) {
<p class="contract-info">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" data-supported-dps="24x24" fill="red" class="contract-svg" width="24" height="24" focusable="false">
<path d="M13 13h5v1h-5zm5-5H6v3h12zm-5 8h5v-1h-5zm9-12v13a3 3 0 01-3 3H5a3 3 0 01-3-3V4zm-2 2H4v11a1 1 0 001 1h14a1 1 0 001-1zm-9 7H6v3h5z"></path>
</svg>
{{ user().contracts?.length }} @if(user().contracts?.length == 1) { contract } @else { contracts }
</p>
}
Neither does this:
@if(user().contracts && user().contracts.length > 0) {
<p class="contract-info">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" data-supported-dps="24x24" fill="red" class="contract-svg" width="24" height="24" focusable="false">
<path d="M13 13h5v1h-5zm5-5H6v3h12zm-5 8h5v-1h-5zm9-12v13a3 3 0 01-3 3H5a3 3 0 01-3-3V4zm-2 2H4v11a1 1 0 001 1h14a1 1 0 001-1zm-9 7H6v3h5z"></path>
</svg>
{{ user().contracts?.length }} @if(user().contracts?.length == 1) { contract } @else { contracts }
</p>
}
But this does:
@if(user().contracts; as contracts) {
@if(contracts && contracts.length > 0) {
<p class="contract-info">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" data-supported-dps="24x24" fill="red" class="contract-svg" width="24" height="24" focusable="false">
<path d="M13 13h5v1h-5zm5-5H6v3h12zm-5 8h5v-1h-5zm9-12v13a3 3 0 01-3 3H5a3 3 0 01-3-3V4zm-2 2H4v11a1 1 0 001 1h14a1 1 0 001-1zm-9 7H6v3h5z"></path>
</svg>
{{ contracts?.length }} @if(contracts?.length == 1) { contract } @else { contracts }
</p>
}
}
If I do:
contracts && contracts?.length > 0
It fails, bizarrely. (same object undefined message)
![Screenshot 2024-06-13 at 07 44 50](https://private-user-images.githubusercontent.com/39380005/339242075-f2b7cb2f-8036-48ce-8f09-0cb1c8350ab8.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTg3Mjg4MTcsIm5iZiI6MTcxODcyODUxNywicGF0aCI6Ii8zOTM4MDAwNS8zMzkyNDIwNzUtZjJiN2NiMmYtODAzNi00OGNlLThmMDktMGNiMWM4MzUwYWI4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MTglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjE4VDE2MzUxN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTk3MzgxOTNhMzFjMDY4YzZiYjQ2Njk4NjlkYTA3OWY2NjdlN2M1NmIyOTBjNTY5NDk3ODJiY2U4ZGRiNGEzNjkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.j1QHeL3Iomz1FKihKHFR9XVzZE9-MUOwQevwGbmkSfI)
I think this is a typescript issue, as it's not doing a smart casting of the second condition against the '>' check.
from angular.
Related Issues (20)
- JS Exception prevents downloading Tutorial Code HOT 1
- Allow Angular Templates to use the html template function from Lit? HOT 1
- "ng build" hangs HOT 1
- Control Flow - Allow wrapping element for `@for`
- Looking for list of built-in pipes HOT 1
- Support video thumbnails for Cloudinary image loader
- Issue with using @for built-in template syntax while removing dynamic form array elements HOT 3
- Issues using angular cdk drag and drop with angular form array HOT 1
- @for(ID of IDs; track ID) and NG0956 - provide a way to prevent warning when tracking by item is legit scenario HOT 3
- The reset method of FormControl is setting the value to null instead of setting it to the initial value. HOT 2
- Example images from the Housing Location Tutorial missing HOT 1
- signals (or function calls in the templates) in language service HOT 3
- Detached DOM nodes HOT 4
- The `@angular/localize API` link directs to a 404 HOT 3
- Link gets broken with space character in its end HOT 1
- solution HOT 1
- Missing documentation for global `ng` variable HOT 1
- Some examples not showing in router API docs page HOT 1
- Cannot run test with ChromeHeadless in Continuous Integration HOT 1
- Missing documentation for InjectionToken HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular.