@@ -1860,7 +1860,38 @@ function createCompletionEntry(
1860
1860
&& ! ( type . flags & TypeFlags . BooleanLike )
1861
1861
&& ! ( type . flags & TypeFlags . Union && find ( ( type as UnionType ) . types , type => ! ! ( type . flags & TypeFlags . BooleanLike ) ) )
1862
1862
) {
1863
- if ( type . flags & TypeFlags . StringLike || ( type . flags & TypeFlags . Union && every ( ( type as UnionType ) . types , type => ! ! ( type . flags & ( TypeFlags . StringLike | TypeFlags . Undefined ) || isStringAndEmptyAnonymousObjectIntersection ( type ) ) ) ) ) {
1863
+ // Check if we should use quotes for string-like types
1864
+ let shouldUseQuotes = false ;
1865
+
1866
+ if ( type . flags & TypeFlags . StringLike ) {
1867
+ // Direct string-like type
1868
+ shouldUseQuotes = true ;
1869
+ } else if ( type . flags & TypeFlags . Union ) {
1870
+ const unionType = type as UnionType ;
1871
+ // Check if all types are string-like or undefined (original logic)
1872
+ const allTypesAreStringLikeOrUndefined = every ( unionType . types , type =>
1873
+ ! ! ( type . flags & ( TypeFlags . StringLike | TypeFlags . Undefined ) || isStringAndEmptyAnonymousObjectIntersection ( type ) )
1874
+ ) ;
1875
+
1876
+ if ( allTypesAreStringLikeOrUndefined ) {
1877
+ shouldUseQuotes = true ;
1878
+ } else {
1879
+ // Check if the union contains string-like types that users would typically provide as strings
1880
+ // This handles cases like Preact's Signalish<string | undefined> = string | undefined | SignalLike<string | undefined>
1881
+ const hasStringLikeTypes = some ( unionType . types , type => ! ! ( type . flags & TypeFlags . StringLike ) ) ;
1882
+ const hasNonObjectTypes = some ( unionType . types , type =>
1883
+ ! ! ( type . flags & ( TypeFlags . StringLike | TypeFlags . Undefined | TypeFlags . Null ) )
1884
+ ) ;
1885
+
1886
+ // If the union has string-like types and at least some primitive types (not just objects),
1887
+ // prefer quotes since users commonly want to provide string values
1888
+ if ( hasStringLikeTypes && hasNonObjectTypes ) {
1889
+ shouldUseQuotes = true ;
1890
+ }
1891
+ }
1892
+ }
1893
+
1894
+ if ( shouldUseQuotes ) {
1864
1895
// If is string like or undefined use quotes
1865
1896
insertText = `${ escapeSnippetText ( name ) } =${ quote ( sourceFile , preferences , "$1" ) } ` ;
1866
1897
isSnippet = true ;
0 commit comments