-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
feat: autocomplete #11
Conversation
4d02f31
to
2552852
Compare
Fixed |
Hi @ablankenship10 , thanks for your pr, it fixes the ts issue! However, let's please send all of our commits to the same PR in order to keeps things organized ;). The latest commit:
Remaining issues:
// en.json
{
"hello": "hello",
"talkr": {
"test": "talkr works"
},
"company": {
"employee": {
"tech": "tech team",
"sales": "sales team"
}
},
}
// .tsx file:
type KeyPrefix<T extends string> = T extends "" ? "" : `.${T}`;
export type KeyPath<T> = (
T extends object
? {
[K in Exclude<keyof T, symbol>]: `${K}${KeyPrefix<KeyPath<T[K]>>}`;
}[Exclude<keyof T, symbol>]
: ""
) extends infer D
? Extract<D, string>
: never;
type Path = KeyPath<typeof en>
function getString(path: Path) {
let result: any = obj
path.split(".").forEach((k) => {
if (!result[k]) return;
return (result = result[k]);
});
return typeof result === "string" ? result : null
}
export default function App() {
return (
<>
<h1>{getString("company.employee.sales")}</h1>
</>
);
}
When hardcoding the object const schemaLanguage = {hello: "hello", etc.}, the autocomplete works! So we're not far from success... But I don't see why it doesn't work yet. |
|
Closes #10 The autocomplete now works with hard-coded strings, concatenation or variables. In order to avoid breaking changes and performance issues for huge json files, the autocompletion is optional, and must be configured in a small |
Start autocomplete feature and refactor code. The autocomplete currently displays all the available paths. It should only display direct child nodes (
user
=>user.describe
=>user.describe.complex / user.describe.simple
instead of immediately displaying final paths:user.describe.complex, user.describe.simple
).The pr also needs to fix the
Property 'split' does not exist on type 'never'
issue oncurrentKey.split
inT
function.Any help welcome.