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

Weak inference of String Literal Types by const #27540

Closed
takefumi-yoshii opened this issue Oct 4, 2018 · 5 comments
Closed

Weak inference of String Literal Types by const #27540

takefumi-yoshii opened this issue Oct 4, 2018 · 5 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@takefumi-yoshii
Copy link

takefumi-yoshii commented Oct 4, 2018

Needless to say, below code infferd as String Literal Types.

export const INCREMENT = "INCREMENT"
export const SET_COUNT = "SET_COUNT" as "SET_COUNT"
// result of infer
const INCREMENT: "INCREMENT"
const SET_COUNT: "SET_COUNT"

When put them in the object, It is no longer as String Literal Types without assertion.
Is it correct to be interpreted as weak inference?

const object = {
  INCREMENT,
  SET_COUNT
}
// result of infer
const object: {
  INCREMENT: string;
  SET_COUNT: "SET_COUNT";
}

And this problem can avoid below code.

const object = {
  INCREMENT: INCREMENT as (typeof INCREMENT),
  SET_COUNT
}
// result of infer
const object: {
  INCREMENT: "INCREMENT";
  SET_COUNT: "SET_COUNT";
}

I am waiting for reply. Best reguards.

@jack-williams
Copy link
Collaborator

I think the solution to this is covered by #10195

@takefumi-yoshii
Copy link
Author

@jack-williams thanks! I'll track them.

@takefumi-yoshii
Copy link
Author

umm...Is the pointer reference strength different depending on whether assertion is present or not?

@ahejlsberg
Copy link
Member

See #11126 for a description of this behavior.

@ahejlsberg ahejlsberg added the Question An issue which isn't directly actionable in code label Oct 4, 2018
@takefumi-yoshii
Copy link
Author

@ahejlsberg thanks for reply. I understood about Widening and non-widening. I'll write some localized post about them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

3 participants