Skip to content

Conversation

Seung-wan
Copy link
Contributor

i think Type Declaration is type-safe than Type Assertion.

interface CounterState { value: number } // Type Declaration const initialState: CounterState = { value: 0 } const initialState: CounterState = { value: 0, id: 1 } // Error: ... // Type Assertion const initialState = { value: 0 } as CounterState const initialState = { value: 0, id: 1 } as CounterState // Not error, but id is not type of CounterState.
@codesandbox
Copy link

codesandbox bot commented Jul 26, 2023

This branch is running in CodeSandbox. Use the links below to review this PR faster.


CodeSandbox logoCodeSandbox logo  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders | Preview

@netlify
Copy link

netlify bot commented Jul 26, 2023

Deploy Preview for redux-starter-kit-docs ready!

Name Link
🔨 Latest commit 2f7b0ef
🔍 Latest deploy log https://app.netlify.com/sites/redux-starter-kit-docs/deploys/64c0c0709bd9960008fb6986
😎 Deploy Preview https://deploy-preview-3621--redux-starter-kit-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 26, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 35e58ec:

Sandbox Source
Vanilla Configuration
Vanilla Typescript Configuration
rsk-github-issues-example Configuration
@examples-query-react/basic Configuration
@examples-query-react/advanced Configuration
@examples-action-listener/counter Configuration
@phryneas
Copy link
Member

No, we show that pattern very deliberately as TypeScript's flow analysis otherwise sometimes gives weird results. See #827

If you want to carry this forward, we'd be happy for a PR that adds a satisfies, but the as is required.

-const initialState = { value: 0 } as CounterState +const initialState = { value: 0 } satisfies CounterState as CounterState
@phryneas
Copy link
Member

Thanks :)

If you have the time: Could you maybe go over the docs and look for other places that we can add that?
I know we have that in a bunch of places, and it would be great if we could keep it consistent.

@Seung-wan
Copy link
Contributor Author

@phryneas
Okay. I think I'll just send out a new PR when I'm done.

@Seung-wan Seung-wan closed this Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants