Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
buschco opened this issue Feb 3, 2025 · 1 comment
Open
Labels
bug Typing: completeness No false positives (type checker claims that there are some errors in the correct program)

Comments

@buschco
Copy link

buschco commented Feb 3, 2025

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

@buschco buschco 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'` Feb 3, 2025
@buschco buschco 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' Feb 3, 2025
@buschco buschco 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'` Feb 3, 2025
@buschco buschco 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' Feb 3, 2025
@buschco buschco 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' Feb 3, 2025
@buschco buschco 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'` Feb 3, 2025
@buschco buschco 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' Feb 3, 2025
@buschco buschco 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 Feb 3, 2025
@SamChou19815
Copy link
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.

@SamChou19815 SamChou19815 added incompleteness Something is missing Typing: completeness No false positives (type checker claims that there are some errors in the correct program) and removed needs triage incompleteness Something is missing labels Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Typing: completeness No false positives (type checker claims that there are some errors in the correct program)
Projects
None yet
Development

No branches or pull requests

2 participants