Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Rule proposal: no-unsafe-optional-property-assignment #5955

Open
Labels
accepting prsGo ahead, send a pull request that resolves this issueenhancement: new plugin ruleNew rule request for eslint-pluginpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin
@JoshuaKGoldberg

Description

@JoshuaKGoldberg

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • My proposal specifically checks TypeScript syntax, or it proposes a check that requires type information to be accurate.
  • My proposal is not a "formatting rule"; meaning it does not just enforce how code is formatted (whitespace, brace placement, etc).
  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Description

Fromhttps://github.com/danielnixon/eslint-plugin-total-functions:

Optional properties (those with a ? after their name) interact badly with TypeScript's structural type system in a way that can lead to unsoundness.
...
This rule bans assignment from one type to another, if:

  • the destination type has an optional property, and
  • the source type has no matching property (either optional or otherwise).

Note that in order to take the function in here, we'll need to include the fixes proposed indanielnixon/eslint-plugin-total-functions#83.

Fail Cases

typeFoo={readonlyfoo:string};typeBar=Foo&{readonlybar?:()=>unknown};constthing={foo:"foo",bar:"bar"};constfoo:Foo=thing;constbar:Bar=foo;if(bar.bar!==undefined){bar.bar();// explodes at runtime}

Pass Cases

typeFoo={readonlyfoo:string};typeBar=Foo&{readonlybar?:()=>unknown};constthing={foo:"foo",bar:"bar"};constfoo:Foo=thing;constbar=foo;//@ts-expect-errorif(bar.bar!==undefined){//@ts-expect-errorbar.bar();// explodes, but now we know!}

Additional Info

Forking conversation out fromdanielnixon/eslint-plugin-total-functions#665.

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancement: new plugin ruleNew rule request for eslint-pluginpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp