Skip to content

How to tell flow that a dynamic string is just like a normal string #9253

Open

Description

@buschco
type Props = $ReadOnly<{
    actionId: string,
    onPress: (args:{dispatch: () => void}) => void
}> | $ReadOnly<{
    actionId?:void,
    onPress: () => void
}>

const A: (p:Props) => void = () => {}

const actionId: string = `1`

A({
    actionId,
    onPress:({dispatch}) => {dispatch()}
           // ^ property `dispatch` is missing in undefined [1]. [incompatible-use]
})

A({
    actionId: ''.concat(''),
    onPress:({dispatch}) => {dispatch()}
           // ^ property `dispatch` is missing in undefined [1]. [incompatible-use]
})

A({
    actionId: '1',
    onPress:({dispatch}) => {dispatch()}
    // no error like it should be
})

Flow version: 0.259.1

Expected behavior

No error.

Actual behavior

Flow treats "dynamic" strings in a different way.

  • Link to Try-Flow or Github repo:

https://flow.org/try/#1N4Igxg9gdgZglgcxALlAIwIZoKYBsD6uEEAztvhgE6UYCe+JADpdhgCYowa5kA0I2KAFcAtiRQAXSkOz9sADwxgJ+NPTbYuQ3BMnTZA+Y2yU4IwRO4A6SFBIrGVDGM7c+h46fNRLuKxJIGWh8MeT0ZfhYlCStpHzNsFBAMIQkIEQwJODAQfiEyfBE4eWw2fDgofDBMsAALfAA3KjgsXGxxZC4eAw0G-GhcWn9aY3wWZldu-g1mbGqJUoBaCRHEzrcDEgBrbAk62kXhXFxJ923d-cPRHEpTgyEoMDaqZdW7vKgoOfaSKgOKpqmDA+d4gB5fMA-P6LCCMLLQbiLOoYCqgh6-GDYRYIXYLSgkRZkCR4jpddwPfJLZjpOBkO4AX34kA0SRWxgABAAFSiwkjsgC87IAJAAlVhsADyUEGAB5gAAdKDs5Xs6JwaAASTYyHZ9lMUAQvEVKvZ0G5Px1AAoqAgSKg2LTHHtalaAJQCgB87IaEDgbHp7v5Xp9fsV9K9AB9hWL2FLZQqlSq1Zq2AB+ZAhthGxPKs0sEh29mWwPB31sMMexWK2z2dkAQStjGQ3N5Je9ZYFRbbwHpVce0FryagWp1eoqCE7AAMAIyTvt1y0Jk1DrXZk15i2Lh1MGq1AOe9nAbdOurF3tQAPzxfGpPKdXD7XsgDkT5s0HmlpfrrXKo3BeQW6Oru+5Boex67meYauleS63vCD46k+05Pj+uZQOa-6ATuzogV6R5Ac6kEXq6uQgA0JgkPeSQNAADFYABMACsACcVjTiA9JAA

Activity

  1. changed the title [-]How to tell flow that a ``tempalte_string`` is the same as `'tempalte_string'`[/-] [+]How to tell flow that a `\`template_string\`` is the same as `'template_string'`[/+] on Feb 3, 2025
  2. changed the title [-]How to tell flow that a `\`template_string\`` is the same as `'template_string'`[/-] [+]How to tell flow that a ````template_string```` is the same as `'template_string'`[/+] on Feb 3, 2025
  3. changed the title [-]How to tell flow that a ````template_string```` is the same as `'template_string'`[/-] [+]How to tell flow that a ```\`template_string\```` is the same as `'template_string'`[/+] on Feb 3, 2025
  4. changed the title [-]How to tell flow that a ```\`template_string\```` is the same as `'template_string'`[/-] [+]How to tell flow that a ` \`template_string\` ` is the same as `'template_string'`[/+] on Feb 3, 2025
  5. changed the title [-]How to tell flow that a ` \`template_string\` ` is the same as `'template_string'`[/-] [+]How to tell flow that a `template_string` is the same as `'template_string'`[/+] on Feb 3, 2025
  6. changed the title [-]How to tell flow that a `template_string` is the same as `'template_string'`[/-] [+]How to tell flow that a ```template_string```` is the same as `'template_string'`[/+] on Feb 3, 2025
  7. changed the title [-]How to tell flow that a ```template_string```` is the same as `'template_string'`[/-] [+]How to tell flow that a \`template_string\` is the same as `'template_string'`[/+] on Feb 3, 2025
  8. changed the title [-]How to tell flow that a \`template_string\` is the same as `'template_string'`[/-] [+]How to tell flow that a dynamic string is just like a normal string[/+] on Feb 3, 2025
  9. SamChou19815 commented on Feb 3, 2025

    @SamChou19815
    Contributor

    This is a result of our contextual typing heuristics. For now, we only use specific syntactic patterns (e.g. only literal) to help pick one of the disjoint union.

    There might be something we can do better here, since TS is able to do that.

  10. added
    Typing: completenessNo false positives (type checker claims that there are some errors in the correct program)
    and removed on Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Typing: completenessNo false positives (type checker claims that there are some errors in the correct program)bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions