중복 옵션 체인
이 경고 카테고리의 철자는 [redundant-optional-chaining]
입니다.
중복 선택적 체인
무슨 일이 일어났나요?
일부 조회는 필요하지 않은 경우 선택적 연쇄를 사용합니다. 열거형 값을 조회하거나 null
또는 undefined
이 될 수 없는 베이스에서 조회를 수행할 때 이러한 문제가 발생할 수 있습니다.
이것이 왜 나쁜가요?
선택적 조회는 일반 조회가 수행하지 않는 런타임 검사를 수행해야 합니다. 이러한 추가 명령어는 항상 중복되는 것으로 판단할 수 없으며 도구에서 최적화할 수도 없습니다. 그러면 런타임 성능 비용이 추가되고 프로그램이 불필요하게 부풀어 오르게 됩니다.
또한 선택적 조회가 체인의 잘못된 베이스에서 수행되었음을 암시하는 경고가 표시될 수도 있습니다. 보다 구체적인 예는 다음 섹션을 참조하세요.
예제
// Main.qml import QtQml QtObject { // Main will either be resolved and always work, or throw an exception or fail to compile enum E { A, B, C } property int i: Main?.A // A url cannot be null or undefined property url u: "" property string s: u?.toString() // Did you mean to make the second lookup optional? property int i: Safe?.Unsafe.i }
이러한 경고를 해결하려면 중복된 선택적 조회를 비선택적 조회로 바꾸세요:
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.