fix(common): fix a Closure compilation issue.
Closure Compiler cannot infer that the swtich statement is exhaustive, which causes it to complain that the method does not always return a value. Work around the problem by throwing an exception in the default case, and using the `: never` type to ensure the code is unreachable.
This commit is contained in:
		
							parent
							
								
									b89e7c2cb7
								
							
						
					
					
						commit
						2e7e935b02
					
				| @ -270,6 +270,13 @@ function getDateTranslation( | |||||||
|       return getLocaleDayPeriods(locale, form, <TranslationWidth>width)[currentHours < 12 ? 0 : 1]; |       return getLocaleDayPeriods(locale, form, <TranslationWidth>width)[currentHours < 12 ? 0 : 1]; | ||||||
|     case TranslationType.Eras: |     case TranslationType.Eras: | ||||||
|       return getLocaleEraNames(locale, <TranslationWidth>width)[date.getFullYear() <= 0 ? 0 : 1]; |       return getLocaleEraNames(locale, <TranslationWidth>width)[date.getFullYear() <= 0 ? 0 : 1]; | ||||||
|  |     default: | ||||||
|  |       // This default case is not needed by TypeScript compiler, as the switch is exhaustive.
 | ||||||
|  |       // However Closure Compiler does not understand that and reports an error in typed mode.
 | ||||||
|  |       // The `throw new Error` below works around the problem, and the unexpected: never variable
 | ||||||
|  |       // makes sure tsc still checks this code is unreachable.
 | ||||||
|  |       const unexpected: never = name; | ||||||
|  |       throw new Error(`unexpected translation type ${unexpected}`); | ||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user