-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Unclear compiler error with map function and number or types #13594
Comments
Another possible workaround is: export namespace DiagnosticSeverity {
/**
* Reports an error.
*/
export const Error: 1 = 1;
/**
* Reports a warning.
*/
export const Warning: 2 = 2;
/**
* Reports an information.
*/
export const Information: 3 = 3;
/**
* Reports a hint.
*/
export const Hint: 4 = 4;
} |
The typing of the const doesn't work for d.ts file generation since the generated d.ts again looks like this: export declare namespace DiagnosticSeverity {
/**
* Reports an error.
*/
const Error: 1;
/**
* Reports a warning.
*/
const Warning: 2;
/**
* Reports an information.
*/
const Information: 3;
/**
* Reports a hint.
*/
const Hint: 4;
} |
const One = 1; // Should behave the same as ExplicitOne
const ExplicitOne: 1 = 1;
type OneOrTwo = 1 | 2;
type Thing = { x: OneOrTwo; }
// Error
let x: Thing = (() => ({ x: One }))();
// OK
let y: Thing = (() => ({ x: ExplicitOne }))(); |
@RyanCavanaugh's example is by design. the two do not behave the same, one is fresh ( The above issue is really a consequence of not using the return type position as an inference location, see #11152. The only place the return type of map is inferred from is the return type, and there is no contextual type there, so you get the widened type instead of the literal one. #11152 tracks that. |
TypeScript Version: 2.1.5
Code
Expected behavior:
No compile error
Interestingly the error disappears if the fat arrow function gets typed:
The text was updated successfully, but these errors were encountered: