AmadeusITGroup / otter

The Otter project is a highly modular framework whose goal is to provide a common platform to accelerate and facilitate the development of runtime customizable Angular based Web Applications
https://amadeusitgroup.github.io/otter/
BSD 3-Clause "New" or "Revised" License
51 stars 38 forks source link

fix: make typings more accurate by avoiding explict cast on consts #2475

Open kpanot opened 1 week ago

kpanot commented 1 week ago

Proposed change

When creating an object that is intended to be read-only, we should let typescript infer the type.

Not good:

interface NamedObjectMaybe {
  name?: string;
}
const UNMOVABLE_OBJECT: NamedObjectMaybe = {
  name: 'unicorn'
};

// UNMOVABLE_OBJECT.name is typed as string | undefined

Nice:

interface NamedObjectMaybe {
  name?: string;
}
const UNMOVABLE_OBJECT = {
  name: 'unicorn'
} as const satisfies NamedObjectMaybe;

// UNMOVABLE_OBJECT.name is typed as 'unicorn' but we still validate that UNMOVABLE_OBJECT matches the interface

Related issues

nx-cloud[bot] commented 1 week ago

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 5108a4f05cc17645620a851f48107d423c0ae67b. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 11 targets - [`nx run-many --target=test-int --parallel 3`](https://cloud.nx.app/runs/YpsJweULj0?utm_source=pull-request&utm_medium=comment) - [`nx run-many --target=build --projects=eslint-plugin --parallel 3`](https://cloud.nx.app/runs/ppxvjxLySZ?utm_source=pull-request&utm_medium=comment) - [`nx run-many --target=test-e2e --parallel 3`](https://cloud.nx.app/runs/lTk7BVphVw?utm_source=pull-request&utm_medium=comment) - [`nx run-many --target=publish --parallel 3 --nx-bail --userconfig .verdaccio/conf/.npmrc-logged --tag=latest --@o3r:registry=http://127.0.0.1:4873 --@ama-sdk:registry=http://127.0.0.1:4873 --@ama-terasu:registry=http://127.0.0.1:4873 --@o3r-training:registry=http://127.0.0.1:4873`](https://cloud.nx.app/runs/QGkmybI2Az?utm_source=pull-request&utm_medium=comment) - [`nx run-many --target=build --parallel 3`](https://cloud.nx.app/runs/FnOIlFm0Um?utm_source=pull-request&utm_medium=comment) - [`nx affected --target=test --parallel 3 --cacheDirectory=D:\a\otter\otter/.cache/jest --base=remotes/origin/main --collectCoverage`](https://cloud.nx.app/runs/FRDNbmz80R?utm_source=pull-request&utm_medium=comment) - [`nx affected --target=lint --parallel 3 --base=remotes/origin/main --configuration ci`](https://cloud.nx.app/runs/sMv0R9Xjkd?utm_source=pull-request&utm_medium=comment) - [`nx affected --target=test --parallel 3 --cacheDirectory=/home/runner/work/otter/otter/.cache/jest --base=remotes/origin/main --collectCoverage`](https://cloud.nx.app/runs/oE3BXqFYya?utm_source=pull-request&utm_medium=comment) - [`nx run-many --target=documentation --parallel 3`](https://cloud.nx.app/runs/C5La1cKZr4?utm_source=pull-request&utm_medium=comment) - [`nx run ama-sdk-schematics:build-swagger`](https://cloud.nx.app/runs/7RU5UBKrWs?utm_source=pull-request&utm_medium=comment) - [`nx run-many --target=build-swagger --parallel 3`](https://cloud.nx.app/runs/9NS5zkTzz0?utm_source=pull-request&utm_medium=comment)

Sent with 💌 from NxCloud.

codecov[bot] commented 1 week ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 0.00%. Comparing base (0042a21) to head (5108a4f).

:white_check_mark: All tests successful. No failed tests found.

Additional details and impacted files

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

matthieu-crouzet commented 1 week ago