Это видео недоступно.
Сожалеем об этом.
Is your Component Ready for Strict Mode
HTML-код
- Опубликовано: 22 июн 2022
- With strict mode enabled by default, we must acknowledge that there is nothing more tiresome than using a component that is poorly typed. As we develop our components we must consider the implications of our Input types for developers that have strict mode enabled.
The key point: just defining the Input types isn't enough to avoid type failures.
Do you want to support shorthand boolean attributes? It can't just be boolean.
Will Inputs be set with the async pipe? Do you handle the initial null values?
I will demonstrate the use cases for ngAcceptInputType along with Input coercion, drawing on my experience of preparing the "ag-grid-angular" for use in strict applications.
As Inputs are a fundamental part of Angular this will impact every developer once their application enables strict mode. I would hate for developers to resort to any when there are Angular features to maintain fully typed components.
Question asked about using Union Types and answered by Stephen, and providing more context:
Question: Why not just type the input with a union type?
Answer: Because then throughout your component you would be coding against the wrong type. You only need the empty string and null to get the value into your component and set as the boolean.
GitHub Repo: github.com/Ste...
Angular Template Type Checking Docs: angular.io/gui...
AG Grid: ag-grid.com/
𝚙𝚛𝚘𝚖𝚘𝚜𝚖 😜